Skip to content

Commit

Permalink
refacotr: making code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Dec 19, 2023
1 parent 68a553a commit c720a25
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 52 deletions.
22 changes: 22 additions & 0 deletions kreacher/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kreacher

import (
td "github.com/gotd/td/telegram"
redis "github.com/redis/go-redis/v9"
tele "gopkg.in/telebot.v3"
)

type Kreacher struct {
RedisDB *redis.Client
KreacherBot *tele.Bot
UserBot *td.Client
}

func NewKreacher(redisDB *redis.Client, kreacherBot *tele.Bot, userBot *td.Client) *Kreacher {
return &Kreacher{
RedisDB: redisDB,
KreacherBot: kreacherBot,
UserBot: userBot,
}

}
24 changes: 0 additions & 24 deletions kreacher/clients.go

This file was deleted.

6 changes: 3 additions & 3 deletions kreacher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/joho/godotenv"
)

type Config struct {
type BotConfig struct {
APIID int
APIHash string
BotToken string
Expand All @@ -29,7 +29,7 @@ type Config struct {
RedisPort int
}

func NewConfig() *Config {
func NewConfig() *BotConfig {
err := godotenv.Load("../.env")
if err != nil {
fmt.Println("No .env file found")
Expand All @@ -54,7 +54,7 @@ func NewConfig() *Config {
redisPassword := os.Getenv("REDIS_PASSWORD")
redisPort, _ := strconv.Atoi(os.Getenv("REDIS_PORT"))

return &Config{
return &BotConfig{
APIID: apiID,
APIHash: apiHash,
BotToken: botToken,
Expand Down
23 changes: 22 additions & 1 deletion kreacher/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
package kreacher

import (
"fmt"
"time"

td "github.com/gotd/td/telegram"
redis "github.com/redis/go-redis/v9"
tele "gopkg.in/telebot.v3"
)

func main() {
err := kbot.SetCommands([]tele.Command{
redisDB := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", NewConfig().RedisHost, NewConfig().RedisPort),
Password: NewConfig().RedisPassword,
DB: 0, // use default DB
Protocol: 3, // specify 2 for RESP 2 or 3 for RESP 3
})

kreacherBot, _ := tele.NewBot(tele.Settings{
Token: NewConfig().BotToken,
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
})

userBot := td.NewClient(NewConfig().APIID, NewConfig().APIHash, td.Options{})

kreacher := NewKreacher(redisDB, kreacherBot, userBot)

err := kreacher.KreacherBot.SetCommands([]tele.Command{
{Text: "config", Description: "Set the bot's configuration"},
{Text: "help", Description: "How to use this"},
{Text: "leave", Description: "Leave the voice chat"},
Expand Down
23 changes: 0 additions & 23 deletions kreacher/setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion kreacher/tasks/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ async def audio_ended(client, source):
async def video_ended(client, source):
logging.info(f"video ended: {source}")
os.remove(source)
"""
"""

0 comments on commit c720a25

Please sign in to comment.