Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrek8 authored Dec 3, 2023
1 parent a74ad23 commit 6c29665
Show file tree
Hide file tree
Showing 21 changed files with 905 additions and 0 deletions.
68 changes: 68 additions & 0 deletions gobot/cmd/main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"gobot/internal/commands"
"gobot/internal/handlers/game"
"gobot/internal/handlers/horo"
"gobot/internal/handlers/lightning"
"gobot/internal/handlers/weather"
"gobot/internal/handlers/worl_tour"
"gobot/internal/server"
"gobot/internal/setup"
"log"
"os"
)

func main() {

bot := setup.Botstart(os.Getenv("BOT-TOKEN"))
//bot.Debug = true
setup.Webhooksstart(bot)

com := commands.CommandsReq()
_, err := bot.Request(com)
if err != nil {
log.Fatal(err)
}
updates := bot.ListenForWebhook("/" + os.Getenv("BOT-TOKEN"))

go server.Server()

for update := range updates {

if setup.IsNil(update) { // ignore any non-Message updates
continue
}

if setup.IsCommand(update) { // command updates
switch update.Message.Command() {
case "weather":
weather.Weather(bot, update)
case "game":
game.Game(bot, update)
case "horo":
horo.Horo(bot, update)
case "calc":
lightning.Lightning(bot, update)
case "world_tour":
worl_tour.WorldHandler(bot, update)
}
}

if setup.IsText(update) { //text update

//log.Println(update.Message.Text[0], update.Message.Text[len(update.Message.Text)-1])
if setup.IsWeather(update) {
weather.WeatherHandler(bot, update)
}
if setup.IsGame(update) {
game.GameHandler(bot, update)
}
if setup.IsHoro(update) {
horo.Horohandler(bot, update)
}
}

//log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
}
}
8 changes: 8 additions & 0 deletions gobot/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module gobot

go 1.21

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect
)
4 changes: 4 additions & 0 deletions gobot/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
20 changes: 20 additions & 0 deletions gobot/internal/commands/comandsconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package commands

import tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"

var weather = tgbotapi.BotCommand{Command: "/weather", Description: "Погода"}
var game = tgbotapi.BotCommand{Command: "/game", Description: "Игры"}
var horo = tgbotapi.BotCommand{Command: "/horo", Description: "Гороскопы"}
var lightning = tgbotapi.BotCommand{Command: "/calc", Description: "Калькулятор молний"}
var world_tour = tgbotapi.BotCommand{Command: "/world_tour", Description: "Путешествие по миру"}

func CommandsReq() tgbotapi.SetMyCommandsConfig {
commands := tgbotapi.NewSetMyCommands(
weather,
game,
horo,
lightning,
world_tour,
)
return commands
}
49 changes: 49 additions & 0 deletions gobot/internal/consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package consts

// ngrok http --domain=blessed-expert-parakeet.ngrok-free.app 80

//youtubekey = "AIzaSyDMeRhspy2tqx3oepQQ3fVTtmLF-UK7yrY"

var World_tour = map[string]string{
"в Болгарию": "AgACAgIAAxkBAAIEm2VkZAABIaUNvOUIXgF7bIx8jXUmzAACM9ExG94RIEtoSJhkEiDS9AEAAwIAA3MAAzME",
"в Испанию": "AgACAgIAAxkBAAIEmWVkY8-KMUpH1XecNcrG4kLwsj0aAAIw0TEb3hEgS_DtaCpesBvLAQADAgADcwADMwQ",
"на Кубу": "AgACAgIAAxkBAAIEn2VkZLtIhPeQgiwYMZAgGI6OfHgHAAI70TEb3hEgS1TZw6KLFPR0AQADAgADcwADMwQ",
"в Кипр": "AgACAgIAAxkBAAIEmmVkY-rQBC5yQGPe5Kdkgakc4aQzAAIx0TEb3hEgS6Af3-AiiDaPAQADAgADcwADMwQ",
"в Таиланд": "AgACAgIAAxkBAAIEo2VkZvS-yX3ob9SaQoxSw5VCdl3mAAJG0TEb3hEgS-7LKamvAvg-AQADAgADcwADMwQ",
"во Вьетнам": "AgACAgIAAxkBAAIEnmVkZKckwwFyhuCHGXW-WnRMrYtCAAI60TEb3hEgS-5HzHLxCfLcAQADAgADcwADMwQ",
"в Индию": "AgACAgIAAxkBAAIEnWVkZJUzwWyYyGdYhnELgoffNc1yAAI50TEb3hEgSwTYKv2JGxkUAQADAgADcwADMwQ",
"в Тунис": "AgACAgIAAxkBAAIEnGVkZINhYbdlpgk4h2iGPvOb7myZAAI40TEb3hEgS3QJFVsWvzWpAQADAgADcwADMwQ",
"в Армению": "AgACAgIAAxkBAAIEmGVkY7WOizS9i_UnrzKHHvAVmvPMAAIu0TEb3hEgSwiuKTBbVAYbAQADAgADcwADMwQ",
"в Египет": "AgACAgIAAxkBAAIEoGVkZM52GbawfInvx0OA-LI60JuqAAI80TEb3hEgSxDIyiU95iw3AQADAgADcwADMwQ",
"в Турцию": "AgACAgIAAxkBAAIEoWVkZOcCi8OVvbs1h9IpHL-bIXr2AAI90TEb3hEgSzZ58Zys_RnkAQADAgADcwADMwQ",
"в Россию": "AgACAgIAAxkBAAIEomVkZP18kBq7q-xvlEywvGB_Rz1TAAI-0TEb3hEgS-sWRzINA4h9AQADAgADcwADMwQ",
"в Дубай": "AgACAgIAAxkBAAIEkmVkX8vZ3mtgXjfLJnXJ1xEN0S0fAALy0DEb3hEgS1dFvgnzkKD7AQADAgADcwADMwQ",
}

const (
TymenLat = 57.1522
TymenLon = 65.5272
StrLat = 60.72411
StrLon = 77.58138
)

const WeatherEndpoinCurrent = `https://api.openweathermap.org/data/2.5/weather?lat=%f&lon=%f&appid=%s&units=metric&lang=ru`
const WeatherEndpoinDays = `https://api.openweathermap.org/data/2.5/forecast?lat=%f&lon=%f&cnt=%d&appid=%s&units=metric&lang=ru`

var Transcript_dict = map[string]string{
"♉": "Taurus",
"♈": "Aries",
"♎": "Libra",
"♑": "Capricorn",
"♏": "Scorpio",
"♒": "Aquarius",
"♓": "Pisces",
"♍": "Virgo",
"♌": "Leo",
"♊": "Gemini",
"♐": "Sagittarius",
"♋": "Cancer",
"Сегодня": "Today",
"Завтра": "Tomorrow",
"Послезавтра": "Tomorrow02",
}
67 changes: 67 additions & 0 deletions gobot/internal/handlers/game/gamehandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package game

import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"gobot/internal/keyboards/reply"
)

func Game(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewMessage(u.Message.Chat.ID, "Выберите игру")
msg.ReplyMarkup = reply.Gamekeyboard
bot.Send(msg)
}

func GameHandler(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
switch u.Message.Text {
case "⁤Выход⁤":
gameExit(bot, u)
case "⁤Кости⁤":
dice(bot, u)
case "⁤Автомат⁤":
automat(bot, u)
case "⁤Боулинг⁤":
bouling(bot, u)
case "⁤Футбол⁤":
football(bot, u)
case "⁤Баскетбол⁤":
basketball(bot, u)
case "⁤Дартс⁤":
darts(bot, u)
}
}

func gameExit(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewMessage(u.Message.Chat.ID, "Хорошего настроения")
msg.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true)
bot.Send(msg)
}

func automat(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewDiceWithEmoji(u.Message.Chat.ID, "🎰")
bot.Send(msg)
}

func dice(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewDiceWithEmoji(u.Message.Chat.ID, "🎲")
bot.Send(msg)
}

func football(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewDiceWithEmoji(u.Message.Chat.ID, "⚽")
bot.Send(msg)
}

func basketball(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewDiceWithEmoji(u.Message.Chat.ID, "🏀")
bot.Send(msg)
}

func darts(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewDiceWithEmoji(u.Message.Chat.ID, "🎯")
bot.Send(msg)
}

func bouling(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewDiceWithEmoji(u.Message.Chat.ID, "🎳")
bot.Send(msg)
}
65 changes: 65 additions & 0 deletions gobot/internal/handlers/horo/horohandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package horo

import (
"encoding/xml"
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"gobot/internal/consts"
"gobot/internal/keyboards/reply"
"gobot/internal/structures/horo"
"io"
"log"
"net/http"
"reflect"
)

var choose string
var day string

func Horo(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
msg := tgbotapi.NewMessage(u.Message.Chat.ID, "Выберите знак зодиака")
msg.ReplyMarkup = reply.Horokeyboard1
bot.Send(msg)
}

func Horohandler(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
r := []rune(u.Message.Text)
if 9800 <= r[1] && r[1] <= 9811 {
horoDays(string(r[1]), bot, u)
} else {
day = string(r[1 : len(r)-1])

resp, err := http.Get("https://ignio.com/r/export/utf/xml/daily/com.xml")
if err != nil {
log.Println(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
var result horo.Horo
err = xml.Unmarshal(body, &result)
if err != nil {
log.Fatalln(err)
}
s := ""
s += fmt.Sprintf("Гороскоп для %s на %s:\n", choose, day)
a := reflect.ValueOf(result).FieldByName(consts.Transcript_dict[choose]).FieldByName(consts.Transcript_dict[day])
s += fmt.Sprintf("%s", a.Interface())
msg := tgbotapi.NewMessage(u.Message.Chat.ID, s)
msg.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true)
bot.Send(msg)
}
}

func horoDays(r string, bot *tgbotapi.BotAPI, u tgbotapi.Update) {
choose = r
msg := tgbotapi.NewMessage(u.Message.Chat.ID, "Выберите на какой день вы хотите гороскоп")
msg.ReplyMarkup = reply.Horokeyboard2
bot.Send(msg)
}

//func getresult() {
//
//}
22 changes: 22 additions & 0 deletions gobot/internal/handlers/lightning/lightninghandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lightning

import (
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"strconv"
"strings"
)

func Lightning(bot *tgbotapi.BotAPI, u tgbotapi.Update) {
time := strings.Split(u.Message.CommandArguments(), " ")
t := time[len(time)-1]
r, err := strconv.Atoi(t)
if err != nil {
bot.Send(tgbotapi.NewMessage(u.Message.Chat.ID, "Некорректное время\nВведите команду и через пробел время, прошедшее со вспышки до грома"))
return
}
r = r * 340
msg := tgbotapi.NewMessage(u.Message.Chat.ID, fmt.Sprintf("Молния ударила на расстоянии %d метров", r))
msg.ParseMode = "HTML"
bot.Send(msg)
}
Loading

0 comments on commit 6c29665

Please sign in to comment.