Skip to content
Snippets Groups Projects
Commit 57392103 authored by Réthelyi Bálint's avatar Réthelyi Bálint :no_mouth:
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
.idea
app
conf/*
*.env
image: alpine
stages:
- build
- docker
- deploy
go_build:
image: golang:alpine
stage: build
before_script:
- apk add build-base bash
script:
- go build -v -race -ldflags "-linkmode external -extldflags '-static'" -a -o app
artifacts:
paths:
- app
Docker:
stage: docker
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"$REGISTRY_USER\",\"password\":\"$REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination projlab/telebot:latest
Deploy:
image: kroniak/ssh-client
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- 'echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
stage: deploy
script:
- ssh -A -J root@hermes.sch.bme.hu root@192.168.69.118 "mkdir -p ~/development/aranykovacs"
- scp -r -o "ForwardAgent yes" -J root@hermes.sch.bme.hu docker-compose.yml root@192.168.69.118:~/development/aranykovacs/
- ssh -A -J root@hermes.sch.bme.hu root@192.168.69.118 "cd development/aranykovacs; docker pull projlab/telebot; docker-compose up -d"
FROM alpine
COPY app /app/app
WORKDIR /app
ENTRYPOINT ["/app/app"]
\ No newline at end of file
version: "3"
services:
gold_bot:
restart: unless-stopped
container_name: gold_bot
image: projlab/telebot
env_file:
- token.env
\ No newline at end of file
go.mod 0 → 100644
main.go 0 → 100644
package main
import (
"fmt"
"git.sch.bme.hu/insert-epic-projlab-team-name-here/telegram-bot/messages"
"github.com/go-telegram-bot-api/telegram-bot-api"
"gitlab.com/MikeTTh/env"
"log"
)
func main() {
bot, err := tgbotapi.NewBotAPI(env.GetOrDosomething("TOKEN", func() string {
panic("GIVE ME TOKEEEEN")
}))
if err != nil {
log.Panic(err)
}
//bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
if err != nil {
fmt.Println(err)
return
}
for update := range updates {
if update.Message == nil { // ignore any non-Message Updates
continue
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "")
if update.Message.IsCommand() {
cmd := update.Message.Command()
handled := false
for _, c := range messages.Commands {
if c.Name == cmd {
c.Cmd(&msg, &update)
msg.DisableNotification = true
handled = true
break
}
}
if !handled {
msg.DisableNotification = true
msg.Text = "Ezeket tudom 😏:"
for _, c := range messages.Commands {
msg.Text += "\n/" + c.Name
}
msg.ParseMode = "html"
msg.Text += "\n\n<i>(meg diákokat szivatni \U0001F970)</i>"
}
} else {
for _, cw := range messages.Chewers {
if cw(&update, &msg) {
break
}
}
}
if msg.Text != "" {
_, e := bot.Send(msg)
if e != nil {
fmt.Println(e)
}
}
}
}
package messages
import tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
type Chewie func(*tgbotapi.Update, *tgbotapi.MessageConfig) bool
var Chewers = []Chewie{
meme,
}
package messages
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"strings"
)
var FunkyWords = map[string]string{
"uml": "👀",
"whitestar": "👀",
"projlab": "jolesz",
"goldschmidt": "🤴",
"aranykovács": "🤴",
"tooling": "📈",
"fidesz": "🍊",
}
func meme(update *tgbotapi.Update, msg *tgbotapi.MessageConfig) bool {
shouldSend := ""
for word, resp := range FunkyWords {
if strings.Contains(strings.ToLower(update.Message.Text), word) {
shouldSend = resp
}
}
if shouldSend != "" {
msg.Text = shouldSend
msg.ReplyToMessageID = update.Message.MessageID
msg.DisableNotification = true
return true
}
return false
}
package messages
import (
"git.sch.bme.hu/insert-epic-projlab-team-name-here/telegram-bot/server"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
type Command struct {
Name string
Cmd func(msg *tgbotapi.MessageConfig, upd *tgbotapi.Update)
}
var Commands = []Command{
{
Name: "hi",
Cmd: func(msg *tgbotapi.MessageConfig, upd *tgbotapi.Update) {
msg.Text = "hi"
},
},
{
Name: "git",
Cmd: func(msg *tgbotapi.MessageConfig, upd *tgbotapi.Update) {
msg.ParseMode = "html"
msg.Text = "A csapat <a href=\"https://git.sch.bme.hu/insert-epic-projlab-team-name-here\">repoja</a>"
},
},
{
Name: "meet",
Cmd: func(msg *tgbotapi.MessageConfig, upd *tgbotapi.Update) {
msg.Text = "https://meet.google.com/mpv-zvxx-mgi"
},
},
{
Name: "setdocchannel",
Cmd: func(msg *tgbotapi.MessageConfig, upd *tgbotapi.Update) {
server.EditChannel(msg.ChatID)
msg.Text = "kész is haver 👌"
},
},
}
package server
import (
"fmt"
"io/ioutil"
"os"
)
var chanId = int64(0)
func init() {
b, e := ioutil.ReadFile("conf/chan")
if e != nil {
fmt.Println(e)
return
}
str := string(b)
_, e = fmt.Sscanf(str, "%d", &chanId)
if e != nil {
panic(e)
}
}
func EditChannel(id int64) {
chanId = id
e := ioutil.WriteFile("conf/chan", []byte(fmt.Sprintf("%d", chanId)), os.ModePerm)
if e != nil {
fmt.Println(e)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment