forked from kageru/discord-selphybot
Merge branch 'dev' of ssh://git.kageru.moe:23453/kageru/discord-selphybot into dev
This commit is contained in:
commit
0717c68b53
|
@ -1,7 +1,13 @@
|
|||
# Selphybot Changelog
|
||||
Updates are listed in reverse chronological order.
|
||||
|
||||
### 1.1 (dev)
|
||||
### 1.2
|
||||
- added !help command to automatically print a list of all commands and some additional information
|
||||
- finally wrote a readme
|
||||
- updated wink regex
|
||||
- added more misc commands
|
||||
|
||||
### 1.1
|
||||
- cooldowns are now stored per-user, not globally, and no longer apply in DMs
|
||||
- multiple admins can now be defined in the config
|
||||
- admins can now use DM-only commands anywhere
|
||||
|
|
28
README.md
28
README.md
|
@ -1,2 +1,28 @@
|
|||
# discord-selphybot
|
||||
selphyWoo
|
||||
A custom bot for the discord community of [https://twitch.tv/selphy](Selphy).
|
||||
Most of the commands are fairly specific, but the underlying command logic (i. e. the `registerCommand` wrapper) can be reused in other projects to simplify the [https://github.com/bwmarrin/discordgo](discordgo) API bindings. I might release a standalone version of just the wrappers at some point. *Might*.
|
||||
Anyway.
|
||||
|
||||
## Dependencies
|
||||
- go, obviously
|
||||
- [https://github.com/bwmarrin/discordgo](discordgo)
|
||||
- [https://github.com/deckarep/golang-set](golang-set)
|
||||
|
||||
## Usage
|
||||
I doubt anyone will want to run an exact copy of this, but if you do, it works just like any other project. Edit `config.json` as needed, and then run `go build *.go`. No magic involved.
|
||||
More relevant should be the reusable part. By calling `registerCommand` at any point during program execution, a new command can be added. A command is defined as a struct with various properties do control its behavior.
|
||||
- `Trigger string`: a string that is used to trigger the command when it appears in a message. `Type` is used to control how this string is matched.
|
||||
- `Output string`: simple text response for commands that don’t require any advanced logic.
|
||||
- `OutputEmbed *discordgo.MessageEmbed`: if specified, the specified embed will be used as a reply. Overwrites `Output`.
|
||||
- `Type CommandType`: specifies how `Trigger` is matched. Possible values are: `CommandTypePrefix, CommandTypeFullMatch, CommandTypeContains, CommandTypeRegex`. Defaults to Prefix; names should be self-explanatory.
|
||||
- `IgnoreCase bool`: Ignore case when matching `Trigger`. Defaults to false.
|
||||
- `Cooldown int`: cooldown for the command in seconds. 0 (no cooldown) if unspecified.
|
||||
- `OutputIsReply bool`: @mention the user who triggered the command. This requires a `<@%s>` in `Output`. Defaults to false.
|
||||
- `RequiresMention bool`: require @mentioning the bot to trigger the command. This requires a `<@%s>` in `Trigger`. Defaults to false.
|
||||
- `DeleteInput bool`: delete the messages that triggered the command. Requires permissions to manage messages. Defaults to false.
|
||||
- `DMOnly bool`: command can only be used in DMs. Defaults to false.
|
||||
- `AdminOnly bool`: command can only be used by the admins specified in `config.json`. Defaults to false.
|
||||
- `Function func(*discordgo.Session, *discordgo.MessageCreate)`: execute a custom function when the command is triggered and pass the Session and MessageCreate event to that function. Ignores all other options except the matching-related ones and `Trigger`. Defaults to nil.
|
||||
|
||||
It should be noted that admin users can use DMOnly commands everywhere and are unaffected by cooldowns.
|
||||
|
||||
|
|
31
command.go
31
command.go
|
@ -203,3 +203,34 @@ func giveAgeRole(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getHelpEmbed() *discordgo.MessageEmbed {
|
||||
commandList := "Im Folgenden findest du eine automatisch generierte Liste aller Commands. Um herauszufinden, was sie tun, probiere sie aus oder lies den Source Code (siehe unten).\n```"
|
||||
for _, command := range commands {
|
||||
if command.Type != CommandTypeRegex {
|
||||
commandList += "- " + command.Trigger + "\n"
|
||||
}
|
||||
}
|
||||
commandList += "```"
|
||||
embed := &discordgo.MessageEmbed{
|
||||
Author: &discordgo.MessageEmbedAuthor{},
|
||||
Color: 0xffb90f,
|
||||
Description: "__Hilfe__",
|
||||
Fields: []*discordgo.MessageEmbedField {
|
||||
&discordgo.MessageEmbedField {
|
||||
Name: "__Commands__",
|
||||
Value: commandList,
|
||||
Inline: true,
|
||||
},
|
||||
&discordgo.MessageEmbedField {
|
||||
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]),
|
||||
Inline: true,
|
||||
},
|
||||
},
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||
URL: "https://static-cdn.jtvnw.net/emoticons/v1/1068185/3.0",
|
||||
},
|
||||
}
|
||||
return embed
|
||||
}
|
||||
|
|
1
main.go
1
main.go
|
@ -70,6 +70,7 @@ func addCommands() {
|
|||
|
||||
// Information
|
||||
registerCommand(Command{Trigger: "!welcome", OutputEmbed: getWelcomeEmbed(), Type: CommandTypeFullMatch, DMOnly: true})
|
||||
registerCommand(Command{Trigger: "!help", OutputEmbed: getHelpEmbed(), Type: CommandTypeFullMatch, DMOnly: true})
|
||||
|
||||
// Admin and/or debug
|
||||
registerCommand(Command{Trigger: "<@%s> <3", Output: "<@%s> <3", Type: CommandTypeFullMatch, AdminOnly: true, OutputIsReply: true, RequiresMention: true})
|
||||
|
|
Loading…
Reference in New Issue
Block a user