Skip to content
Snippets Groups Projects
Commit 771a428c authored by Levatax's avatar Levatax
Browse files

First release, not working yet

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #833 failed
go-voice-bot.exe
\ No newline at end of file
package main
import (
log "git.randomchars.net/FreeNitori/Log"
"os"
)
func cleanup() {
if err := session.Close(); err != nil {
log.Fatalf("Error while closing session, %s", err)
os.Exit(1)
}
}
package main
import (
embedutil "git.randomchars.net/FreeNitori/EmbedUtil"
multiplexer "git.randomchars.net/FreeNitori/Multiplexer"
)
func init() {
m.Route(&multiplexer.Route{
Pattern: "sanae",
AliasPatterns: []string{},
Description: "Placeholder command.",
Category: system,
Handler: func(context *multiplexer.Context) {
embed := embedutil.New("About", "Sanae")
embed.AddField("Sanae", "Sanae Sanae Sanae Sanae Sanae", false)
embed.Color = 0x777777
context.SendEmbed("", embed)
},
})
}
go.sum 0 → 100644
git.randomchars.net/FreeNitori/EmbedUtil v1.0.1 h1:ig8jaH76aTm1BR5eKU+Ly/qwX4XE3X59yscR75Xa58E=
git.randomchars.net/FreeNitori/EmbedUtil v1.0.1/go.mod h1:YOl1zIPQobbJ2TI5z+mQyd0B7ZD7AyqhbNdsn36LjPk=
git.randomchars.net/FreeNitori/Log v1.0.0 h1:xifupyu15si9/5oNwLUz8aKMEiyvdlEMCiCq1VW5jdQ=
git.randomchars.net/FreeNitori/Log v1.0.0/go.mod h1:d2oS6xzbzH2YIb7x2ZRYVaaLAgEqBTmu6BCqDcfyzzU=
git.randomchars.net/FreeNitori/Multiplexer v1.0.10 h1:OSeqUER1EVosbHipcRtExwawIXZChEc8gJrrYgd//hY=
git.randomchars.net/FreeNitori/Multiplexer v1.0.10/go.mod h1:wXHDJdlKFC15Bh+f0FsFuQKTXyTxVIfkTt749oDcSk0=
github.com/bwmarrin/discordgo v0.23.2 h1:BzrtTktixGHIu9Tt7dEE6diysEF9HWnXeHuoJEt2fH4=
github.com/bwmarrin/discordgo v0.23.2/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
package main
import (
multiplexer "git.randomchars.net/FreeNitori/Multiplexer"
log "git.randomchars.net/FreeNitori/Log"
)
func init() {
m.VoiceStateUpdate = append(m.VoiceStateUpdate, handleVoiceUpdate)
}
func handleVoiceUpdate(context *multiplexer.Context) {
if context.Channel == nil {
return
}
if context.Channel.ID == "783703981620723762" {
log.Infof("%s joined click me channel", context.Member.User.Username)
}
}
\ No newline at end of file
main.go 0 → 100644
package main
import (
"flag"
"fmt"
log "git.randomchars.net/FreeNitori/Log"
multiplexer "git.randomchars.net/FreeNitori/Multiplexer"
"github.com/bwmarrin/discordgo"
"github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
)
var session *discordgo.Session
var m = multiplexer.New()
var system = multiplexer.NewCategory("System", "System-related utilities.")
func main() {
flag.Parse()
if len(flag.Args()) != 1 {
fmt.Println("expecting 1 argument: token")
os.Exit(1)
}
// Set discordgo log handler
discordgo.Logger = func(msgL, _ int, format string, a ...interface{}) {
var level logrus.Level
switch msgL {
case discordgo.LogDebug:
level = logrus.DebugLevel
case discordgo.LogInformational:
level = logrus.InfoLevel
case discordgo.LogWarning:
level = logrus.WarnLevel
case discordgo.LogError:
level = logrus.ErrorLevel
}
log.Instance.Log(level, fmt.Sprintf(format, a...))
}
// Set command not found handler
multiplexer.NoCommandMatched = func(context *multiplexer.Context) {
return
}
// Configure session
if s, err := discordgo.New(); err != nil {
log.Fatalf("Error while creating session, %s", err)
os.Exit(1)
} else {
session = s
}
session.UserAgent = "DiscordBot (ticket-bot)"
session.Token = "Bot " + flag.Arg(0)
session.ShouldReconnectOnError = true
session.Identify.Intents = discordgo.IntentsAllWithoutPrivileged
// Open session
if err := session.Open(); err != nil {
log.Fatalf("Error while opening session, %s", err)
os.Exit(1)
}
// Setup multiplexer
m.SessionRegisterHandlers(session)
m.Prefix = "!"
m.Categories = append(m.Categories, system)
// Output message
log.Infof("Logged in as %s#%s (%s).",
session.State.User.Username,
session.State.User.Discriminator,
session.State.User.ID)
if application, err := session.Application("@me"); err != nil {
log.Fatalf("Unable to get application, %s", err)
os.Exit(1)
} else {
log.Infof("Invite URL: https://discord.com/oauth2/authorize?client_id=%s&scope=bot&permissions=8", application.ID)
}
// Signal handling
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, os.Interrupt, os.Kill)
var exit int
func() {
for {
currentSignal := <-signalChannel
switch currentSignal {
case os.Interrupt:
exit = 0
println()
log.Info("Gracefully exiting.")
return
default:
exit = 0
log.Info("Gracefully exiting.")
return
}
}
}()
switch exit {
case 0:
cleanup()
default:
os.Exit(exit)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment