gofmt all the things

This commit is contained in:
kageru 2019-01-10 00:16:39 +01:00
parent 6e7229d787
commit 4566ffc230
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
7 changed files with 381 additions and 387 deletions

View File

@ -4,6 +4,7 @@ Updates are listed in reverse chronological order.
### 1.4 (dev) ### 1.4 (dev)
- a copy of each deleted message is now send via DM to the author (suggested by CommanderLook) - a copy of each deleted message is now send via DM to the author (suggested by CommanderLook)
- seasonal fluff - seasonal fluff
- finally use gofmt
### 1.3 ### 1.3
- use global array of pointers to commands to allow easier modification and avoid unnecessary memcpy - use global array of pointers to commands to allow easier modification and avoid unnecessary memcpy

View File

@ -4,10 +4,10 @@ import (
"fmt" "fmt"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/deckarep/golang-set" "github.com/deckarep/golang-set"
"strings"
"time"
"log" "log"
"regexp" "regexp"
"strings"
"time"
) )
type CommandType int type CommandType int
@ -20,13 +20,13 @@ const (
CommandTypeContains CommandType = 3 CommandTypeContains CommandType = 3
) )
/* /*
This struct represents a command object. This struct represents a command object.
The options should be self-explanatory, but they are also explained in the readme. The options should be self-explanatory, but they are also explained in the readme.
A struct can be initialized by passing any number of its attributes as parameters. A struct can be initialized by passing any number of its attributes as parameters.
Everything not set will be set to the go-usual defaults ("" for string, 0 for int, false for bool, nil for the rest) Everything not set will be set to the go-usual defaults ("" for string, 0 for int, false for bool, nil for the rest)
Any command that has a Trigger is valid (but useless if nothing else is specified) Any command that has a Trigger is valid (but useless if nothing else is specified)
*/ */
type Command struct { type Command struct {
Trigger string // must be specified Trigger string // must be specified
Output string // no output if unspecified Output string // no output if unspecified
@ -45,7 +45,6 @@ type Command struct {
UsersOnCooldown mapset.Set // don’t set this manually (it’s overwritten anyway) UsersOnCooldown mapset.Set // don’t set this manually (it’s overwritten anyway)
} }
// Performs basic input validation on a given command and adds it to the global command array // Performs basic input validation on a given command and adds it to the global command array
func registerCommand(command Command) { func registerCommand(command Command) {
if command.Trigger == "" { if command.Trigger == "" {
@ -59,13 +58,13 @@ func registerCommand(command Command) {
commands = append(commands, &command) commands = append(commands, &command)
} }
/* /*
Any message that the bot can read is evaluated here. Any message that the bot can read is evaluated here.
The message is matched against each of the command triggers depending on the respective match type. The message is matched against each of the command triggers depending on the respective match type.
If one of the commands matches, execute that command and return. If one of the commands matches, execute that command and return.
Only one command can be executed per message. Earlier defined commands take precedence. Only one command can be executed per message. Earlier defined commands take precedence.
This is a deliberate choice (for now). This is a deliberate choice (for now).
*/ */
func evaluateMessage(s *discordgo.Session, m *discordgo.MessageCreate) { func evaluateMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID { if m.Author.ID == s.State.User.ID {
log.Printf("<Self> %s", m.Content) log.Printf("<Self> %s", m.Content)
@ -105,10 +104,10 @@ func evaluateMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
} }
} }
/* /*
Executes the given command on the given message and session. Executes the given command on the given message and session.
Sets command cooldowns if necessary and also clears them again. Sets command cooldowns if necessary and also clears them again.
*/ */
func executeCommand(session *discordgo.Session, message *discordgo.MessageCreate, command *Command) { func executeCommand(session *discordgo.Session, message *discordgo.MessageCreate, command *Command) {
if isAdmin(message.Author) || // no restrictions for admins if isAdmin(message.Author) || // no restrictions for admins
(!command.AdminOnly && (isDM(session, message) || !command.UsersOnCooldown.Contains(message.Author.ID)) && (!command.AdminOnly && (isDM(session, message) || !command.UsersOnCooldown.Contains(message.Author.ID)) &&
@ -161,12 +160,12 @@ func generateReply(message *discordgo.MessageCreate, command *Command) string {
return output return output
} }
/* /*
Any message passed to this method will be redirected to config.ModChannel. Any message passed to this method will be redirected to config.ModChannel.
This is useful for anonymous complaints or similar messages. This is useful for anonymous complaints or similar messages.
*/ */
func redirectComplaint(s *discordgo.Session, m *discordgo.MessageCreate) { func redirectComplaint(s *discordgo.Session, m *discordgo.MessageCreate) {
embed := &discordgo.MessageEmbed { embed := &discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{}, Author: &discordgo.MessageEmbedAuthor{},
Color: 0xbb0000, Color: 0xbb0000,
Description: m.Content, Description: m.Content,
@ -178,7 +177,7 @@ func redirectComplaint(s *discordgo.Session, m *discordgo.MessageCreate) {
// copy paste programming btw :haHAA: // copy paste programming btw :haHAA:
func redirectComplaintToDM(s *discordgo.Session, m *discordgo.MessageCreate) { func redirectComplaintToDM(s *discordgo.Session, m *discordgo.MessageCreate) {
embed := &discordgo.MessageEmbed { embed := &discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{}, Author: &discordgo.MessageEmbedAuthor{},
Color: 0xbb0000, Color: 0xbb0000,
Description: m.Content, Description: m.Content,
@ -236,13 +235,13 @@ func getHelpEmbed() *discordgo.MessageEmbed {
Author: &discordgo.MessageEmbedAuthor{}, Author: &discordgo.MessageEmbedAuthor{},
Color: 0xffb90f, Color: 0xffb90f,
Description: "__Hilfe__", Description: "__Hilfe__",
Fields: []*discordgo.MessageEmbedField { Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField { &discordgo.MessageEmbedField{
Name: "__Commands__", Name: "__Commands__",
Value: commandList, Value: commandList,
Inline: true, Inline: true,
}, },
&discordgo.MessageEmbedField { &discordgo.MessageEmbedField{
Name: "__Bugs__", Name: "__Bugs__",
Value: fmt.Sprintf("Bei Fragen zum Bot, Vorschlägen, Bugs etc. wende dich bitte an <@%s> oder öffne eine Issue auf https://git.kageru.moe/kageru/discord-selphybot.", config.Admins[0]), Value: fmt.Sprintf("Bei Fragen zum Bot, Vorschlägen, Bugs etc. wende dich bitte an <@%s> oder öffne eine Issue auf https://git.kageru.moe/kageru/discord-selphybot.", config.Admins[0]),
Inline: true, Inline: true,
@ -254,4 +253,3 @@ func getHelpEmbed() *discordgo.MessageEmbed {
} }
return embed return embed
} }

View File

@ -1,8 +1,8 @@
package main package main
import ( import (
"os"
"encoding/json" "encoding/json"
"os"
) )
type Embed struct { type Embed struct {
@ -29,7 +29,6 @@ type Config struct {
RoleCommands map[string]string RoleCommands map[string]string
} }
func readConfig() Config { func readConfig() Config {
file, _ := os.Open("config.json") file, _ := os.Open("config.json")
conf := Config{} conf := Config{}
@ -37,4 +36,3 @@ func readConfig() Config {
file.Close() file.Close()
return conf return conf
} }

View File

@ -52,4 +52,3 @@ func onDM(s *discordgo.Session, m *discordgo.MessageCreate) {
} }
} }
} }

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"fmt"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"log" "log"
"fmt"
) )
func unlockUser(s *discordgo.Session, id string) { func unlockUser(s *discordgo.Session, id string) {

14
main.go
View File

@ -2,11 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"os/signal"
"os"
"syscall"
"log"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"log"
"os"
"os/signal"
"syscall"
) )
var config = readConfig() var config = readConfig()
@ -28,7 +28,7 @@ func main() {
return return
} }
f, err := os.OpenFile("selphybot.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) f, err := os.OpenFile("selphybot.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil { if err != nil {
fmt.Println("Error opening log file:\n", err) fmt.Println("Error opening log file:\n", err)
} }
@ -68,8 +68,7 @@ func addCommands() {
registerCommand(Command{Trigger: "/o\\", Output: "\\o/", Type: CommandTypeFullMatch, Cooldown: 10}) registerCommand(Command{Trigger: "/o\\", Output: "\\o/", Type: CommandTypeFullMatch, Cooldown: 10})
registerCommand(Command{Trigger: "!heil", Output: "(ノ・ェ・)ノ Selphy (ノ・ェ・)ノ", Type: CommandTypeFullMatch, Cooldown: 30}) registerCommand(Command{Trigger: "!heil", Output: "(ノ・ェ・)ノ Selphy (ノ・ェ・)ノ", Type: CommandTypeFullMatch, Cooldown: 30})
registerCommand(Command{Trigger: "ayy", Output: "lmao", Type: CommandTypeFullMatch, Cooldown: 0}) registerCommand(Command{Trigger: "ayy", Output: "lmao", Type: CommandTypeFullMatch, Cooldown: 0})
registerCommand(Command{Trigger: "<:selphyPadoru:525766188240732180>", Output: "<:selphypadoru:526644596558659594> Padoru <:selphypadoru:526644596558659594> Padoru <:selphypadoru:526644596558659594> Pado Padoru <:selphypadoru:526644596558659594>", Type: CommandTypeFullMatch, Cooldown: 10800}) registerCommand(Command{Trigger: "<:selphyDango:531594585424527370>", Output: "<:dango:430669469799677953> :notes: Dango Daikazoku :notes: <:dango:430669469799677953>", Type: CommandTypeFullMatch, Cooldown: 10800})
registerCommand(Command{Trigger: "<:selphyDango:507979223244341267>", Output: "<:dango:430669469799677953> :notes: Dango Daikazoku :notes: <:dango:430669469799677953>", Type: CommandTypeFullMatch, Cooldown: 10800})
registerCommand(Command{Trigger: "praise the sun", Output: "If only I could be so grossly incandescent \\\\[T]/", Type: CommandTypeContains, IgnoreCase: true, Cooldown: 85600}) registerCommand(Command{Trigger: "praise the sun", Output: "If only I could be so grossly incandescent \\\\[T]/", Type: CommandTypeContains, IgnoreCase: true, Cooldown: 85600})
// Information // Information
@ -86,4 +85,3 @@ func addCommands() {
fmt.Printf("Successfully initialized %d commands\n", len(commands)) fmt.Printf("Successfully initialized %d commands\n", len(commands))
log.Printf("Successfully initialized %d commands", len(commands)) log.Printf("Successfully initialized %d commands", len(commands))
} }

View File

@ -1,22 +1,22 @@
package main package main
import ( import (
"github.com/bwmarrin/discordgo"
"fmt" "fmt"
"github.com/bwmarrin/discordgo"
) )
func getWelcomeEmbed() *discordgo.MessageEmbed { func getWelcomeEmbed() *discordgo.MessageEmbed {
return &discordgo.MessageEmbed { return &discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{}, Author: &discordgo.MessageEmbedAuthor{},
Color: 0xffb90f, Color: 0xffb90f,
Description: config.WelcomeEmbed.Message, Description: config.WelcomeEmbed.Message,
Fields: []*discordgo.MessageEmbedField { Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField { &discordgo.MessageEmbedField{
Name: config.WelcomeEmbed.QuestionsTitle, Name: config.WelcomeEmbed.QuestionsTitle,
Value: config.WelcomeEmbed.QuestionsText, Value: config.WelcomeEmbed.QuestionsText,
Inline: true, Inline: true,
}, },
&discordgo.MessageEmbedField { &discordgo.MessageEmbedField{
Name: config.WelcomeEmbed.BugsTitle, Name: config.WelcomeEmbed.BugsTitle,
Value: fmt.Sprintf(config.WelcomeEmbed.BugsText, config.Admins[0]), Value: fmt.Sprintf(config.WelcomeEmbed.BugsText, config.Admins[0]),
Inline: true, Inline: true,