Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bot
- import (
- "fmt"
- "time"
- "strconv"
- "strings"
- "github.com/bwmarrin/discordgo"
- "../config"
- )
- var (
- botID string
- )
- func Start() {
- goBot, err := discordgo.New("Bot " + config.Token)
- errCheck("error creating bot session", err)
- user, err := goBot.User("@me")
- errCheck("error retrieving account", err)
- botID = user.ID
- goBot.AddHandler(botInit)
- goBot.AddHandler(commandNewInHandler)
- goBot.AddHandler(commandNewDelHandler)
- err = goBot.Open()
- errCheck("Error opening connection to Discord", err)
- fmt.Println("Bot is running!")
- }
- func errCheck(msg string, err error) {
- if err != nil {
- fmt.Printf("%s: %+v", msg, err)
- panic(err)
- }
- }
- func botInit(discord *discordgo.Session, ready *discordgo.Ready) {
- err := discord.UpdateStatus(0, "A friendly helpful bot!")
- if err != nil {
- errCheck("Error attempting to set my status", err)
- }
- servers := discord.State.Guilds
- fmt.Printf("AnimeHater Bot has started on %d servers", len(servers))
- }
- func commandNewInHandler(discord *discordgo.Session, message *discordgo.MessageCreate) {
- if message.Author.ID == botID || message.Author.Bot {
- return
- }
- if strings.HasPrefix(message.Content, config.BotPrefix) {
- command := strings.TrimPrefix(message.Content, config.BotPrefix)
- if command == "Greetings" {
- _, _ = discord.ChannelMessageSend(message.ChannelID, "Здарова, очередняра!")
- }
- if command == "Time" {
- weekdayRu := make(map[string]string)
- weekdayRu["Monday"] = "Пн"
- weekdayRu["Tuesday"] = "Вт"
- weekdayRu["Wednesday"] = "Ср"
- weekdayRu["Thursday"] = "Чт"
- weekdayRu["Friday"] = "Пт"
- weekdayRu["Saturday"] = "Сб"
- weekdayRu["Sunday"] = "Вс"
- monthRU := make(map[string]string)
- monthRU["January"] = "Январь"
- monthRU["February"] = "Февраль"
- monthRU["March"] = "Март"
- monthRU["April"] = "Апрель"
- monthRU["May"] = "Май"
- monthRU["June"] = "Июнь"
- monthRU["July"] = "Июль"
- monthRU["August"] = "Август"
- monthRU["September"] = "Сентябрь"
- monthRU["October"] = "Октябрь"
- monthRU["November"] = "Ноябрь"
- monthRU["December"] = "Декабрь"
- loc, _ := time.LoadLocation("Europe/Moscow")
- now := time.Now().In(loc)
- _, _ = discord.ChannelMessageSend(
- message.ChannelID, "Текущее время по Москве: " + weekdayRu[now.Weekday().String()] + " " + monthRU[now.Month().String()] + " "+
- strconv.Itoa(now.Day())+ " "+ now.Format("15:04:05"))
- }
- }
- }
- func commandNewDelHandler(discord *discordgo.Session, message *discordgo.MessageDelete) {
- _, _ = discord.ChannelMessageSend(message.ChannelID, "Message\n" + message.Content + "\nwas deleted")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement