Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/comments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Memer Workflow

on: [pull_request]

jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run Memer Action
id: memer

uses: Bhupesh-V/memer-action@master
with:
filter: "new"

- name: Check Outputs
run: |
echo "${{ steps.memer.outputs.meme }}"
echo "${{ steps.memer.outputs.title }}"
echo "${{ steps.memer.outputs.source }}"

- name: Create comment
uses: peter-evans/create-or-update-comment@v1.3.0
id: couc
with:
issue-number: ${{ github.event.number }}
body: |
Thanks for opening this PR/Issue 🤗
Please wait while the maintainer(s) review it

Fun fact:

> **${{ steps.memer.outputs.title }}**
![meme](${{ steps.memer.outputs.meme }})
<sub>ℹ️ <a href="${{ steps.memer.outputs.source }}">Source</a></sub>
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Linters
on:
push:
branches-ignore:
- main
- develop
pull_request:
branches:
- main
Expand Down
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
/bin

# Test binary, built with `go test -c`
*.test
Expand Down
58 changes: 58 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
linters-settings:
errcheck:
check-type-assertions: true
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
check-shadowing: true
enable:
- fieldalignment
nolintlint:
require-explanation: true
require-specific: true

linters:
disable-all: true
enable:
- bodyclose
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- goconst
- gocritic
- gofmt
- goimports
- gomnd
- gocyclo
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- nakedret
- prealloc
- predeclared
- revive
- staticcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- whitespace
- wsl

run:
issues-exit-code: 1
59 changes: 59 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# https://taskfile.dev

version: "3"

env:
CGO_ENABLED: "0"
TARGET_OS: linux
TARGET_ARCH: arm64

TARGET_OS_LIST: linux darwin windows
TARGET_ARCH_LIST: amd64 arm64

APP_NAME: github.com/geekopsua/geekbot

tasks:
fmt:
desc: Run go fmt
cmds:
- go fmt ./cmd
lint:
desc: Run golangci-lint
cmds:
- golangci-lint run ./cmd
test:
desc: Run tests
cmds:
- go test -v -cover ./...

build:
deps:
- fmt
- lint
- test
desc: Build binaries
cmds:
- >-
CGO_ENABLED=${CGO_ENABLED};
GOOS=${TARGET_OS};
GOARCH=${TARGET_ARCH};
echo "Building for ${GOOS}/${GOARCH} ${APP_NAME}:{{.appVersion}}";
go build -o bin/geekbot
-ldflags "-X=${APP_NAME}/cmd.appVersion={{.appVersion}}"

build-all:
deps:
- fmt
- lint
desc: Build binaries for all platforms
cmds:
- >-
for os in ${TARGET_OS_LIST}; do
for arch in ${TARGET_ARCH_LIST}; do
CGO_ENABLED=${CGO_ENABLED}
GOOS=$os
GOARCH=$arch
go build -o bin/geekbot
-ldflags "-X=${APP_NAME}/cmd.appVersion={{.appVersion}}"
done
done
82 changes: 82 additions & 0 deletions cmd/geekbot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"log"
"os"
"time"

"github.com/spf13/cobra"
"gopkg.in/telebot.v3"
)

var (
// Telegram bot token
TeleToken = os.Getenv("TELE_TOKEN")
// Add second variable
seconds = 10
)

// geekbotCmd represents the geekbot command
var geekbotCmd = &cobra.Command{
Use: "geekbot",
Aliases: []string{"start"},
Short: "KBot is a bot for Telegram",
Long: `KBot is a fully functional bot for Telegram.

Created for fun and learning purposes. The main goal is to learn Go and Telegram Bot API.
It's a work in progress, so expect some bugs and missing features.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("geekbot %s started", appVersion)
geekbot, err := telebot.NewBot(telebot.Settings{
URL: "",
Token: TeleToken,
Poller: &telebot.LongPoller{Timeout: time.Duration(seconds) * time.Second},
})
if err != nil {
log.Fatalf("Please check your TELE_TOKEN env variable, %s", err)
}

geekbot.Handle(telebot.OnText, func(m telebot.Context) error {
log.Printf(m.Message().Payload, m.Text())
payload := m.Message().Payload

switch payload {
case "hello":
err = m.Send((fmt.Sprintf("Hello! I'm geekbot %s", appVersion)))
default:
err = m.Send(("Sorry, I don't understand"))

}

return err
})

geekbot.Handle("/help", func(m telebot.Context) error {
payload := m.Message().Payload

log.Print(payload, m.Text())
err = m.Send("How can I help you?")

return err
})

geekbot.Handle("/echo", func(m telebot.Context) error {
payload := m.Message().Payload

log.Print(payload, m.Text())
err = m.Send(payload)

return err
})

geekbot.Start()
},
}

func init() {
rootCmd.AddCommand(geekbotCmd)
}
13 changes: 1 addition & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>

Copyright © 2023 @GeekOpsUA
*/
package cmd

Expand All @@ -10,8 +9,6 @@ import (
"github.com/spf13/cobra"
)



// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "GeekBot",
Expand All @@ -37,15 +34,7 @@ func Execute() {
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.GeekBot.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}


30 changes: 30 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright © 2023 @GeekOpsUA
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// Add app version declaration
var appVersion = "Version"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Long: `Print the version number of the application.
You can use it to check if you have the latest version of the application.
For example:
$ geekbot version`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(appVersion)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
10 changes: 10 additions & 0 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cmd

import "testing"

func TestAppVersion(t *testing.T) {
expected := "Version" // replace with your expected app version
if appVersion != expected {
t.Errorf("appVersion = %s; want %s", appVersion, expected)
}
}
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module github.com/GeekOpsUA/GeekBot
module github.com/geekopsua/geekbot

go 1.20

require (
github.com/spf13/cobra v1.8.0
gopkg.in/telebot.v3 v3.1.4
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
Loading