Permalink
Browse files

TOML config, welcome messages

  • Loading branch information...
1 parent 6a2d688 commit 592750bf486ecd4b0ad4c39d5fc9a8e60289aa6c @brussell98 committed Dec 5, 2016
Showing with 97 additions and 60 deletions.
  1. +1 −1 .gitignore
  2. +2 −1 ChannelConfig.dart
  3. +7 −3 README.md
  4. +38 −12 ayaka.dart
  5. +47 −0 config.example.toml
  6. +0 −41 config.example.yaml
  7. +2 −2 pubspec.yaml
View
@@ -27,5 +27,5 @@ doc/api/
pubspec.lock
# Other
-config.yaml
+config.toml
.atom
View
@@ -7,13 +7,14 @@ class ChannelConfig {
List<String> blacklisted_words;
Map mentions_spam;
Map<String, bool> repeat_spam;
+ Map welcome;
RegExp caps_removal_regex;
Map<String, int> last_message_time = new Map<String, int>();
Map<String, String> last_message_text = new Map<String, String>();
List<String> muted_users = new List<String>();
- ChannelConfig({this.mods, this.whitelist, this.slow_mode, this.caps_removal, this.block_links, this.blacklisted_words, this.mentions_spam, this.repeat_spam}) {
+ ChannelConfig({this.mods, this.whitelist, this.slow_mode, this.caps_removal, this.block_links, this.blacklisted_words, this.mentions_spam, this.repeat_spam, this.welcome}) {
if (this.caps_removal['enabled'] && this.caps_removal['threshold'] < 3)
throw 'The caps block threshold must be at least 3';
caps_removal_regex = new RegExp('[A-Z][A-Z ]{' + (this.caps_removal['threshold'] - 2).toString() + '}[A-Z]');
View
@@ -22,16 +22,15 @@ A feature-rich moderation bot for your Discord channels.
3. [Create an application with a bot user.](https://discordapp.com/developers/applications/me) (Note the token)
-4. Set up the `config.yaml` file.
+4. Set up the `config.toml` file.
5. Add your bot to a server using `https://discordapp.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot`.
-# config.yaml
+# config.toml
- Every channel that you want to moderate must be listed even if no settings are changed.
- All fields are required in each setting.
- As shown in the example file, settings can be overwritten per-channel.
-- Indent by 2 spaces per level.
##### token
The token given on the bot's application page (created above in step 3).
@@ -70,6 +69,10 @@ Remove messages containing many mentions.
Stop users from posting the same message multiple times.
`ignore_case` Treat "ABC" and "abc" the same.
+##### welcome
+Greet new members. (This setting is not available globally)
+`message` The message to send. `{user}` = their username. `{mention}` = mention them. `{server}` = the server's name
+
# Commands
|Command|Args|Example|
@@ -85,3 +88,4 @@ Stop users from posting the same message multiple times.
|!block links | `enable`, `on`, `disable`, `off`, `invites only` to only delete invites, `allow non-embeds` to allow suppressed links | !block links enable, allow non-embeds|
|!mentions spam | `enable`, `on`, `disable`, `off`, `number` of mentions to trigger action, `action` to take (delete, kick, or ban) | !mentions spam 10 ban<br>!repeat spam delete|
|!repeat spam | `enable`, `on`, `disable`, `off`, `ignore case` to ignore case (ABC = abc) | !repeat spam on ignore case<br>!repeat spam disable|
+|!welcome | `disable`, `off`, `message` to greet with | !welcome Welcome to the server {user}!<br>!welcome disable|
View
@@ -1,7 +1,6 @@
-import 'dart:io';
import 'package:discord/discord.dart';
import 'package:discord/discord_vm.dart';
-import 'package:yaml/yaml.dart';
+import 'package:toml/loader/fs.dart';
import 'ChannelConfig.dart';
Client bot;
@@ -11,22 +10,24 @@ Map<String, ChannelConfig> channelConfig = new Map<String, ChannelConfig>();
Map<String, int> last_message_time = new Map<String, int>();
Map<String, String> last_message_text = new Map<String, String>();
final RegExp discord_link_regex = new RegExp(r'discord(\.gg|app\.com\/invite|\.me)\/[A-Za-z0-9\-]+', caseSensitive: false);
-final RegExp link_regex = new RegExp(r'<?(https?:\/\/(?:\S+\.|(?![\s]+))[^\s\.]+\.[^\s]{2,}|\S+\.[^\s]+\.[^\s]{2,})>?', caseSensitive: false);
+final RegExp link_regex = new RegExp(r'<?(https?:\/\/(?:\S+\.|(?![\s]+))[^\s\.]+\.\S{2,}|\S+\.\S+\.\S{2,})>?', caseSensitive: false);
main() async {
- YamlMap config = loadYaml(await new File('config.yaml').readAsString());
+ FilesystemConfigLoader.use();
+ var config = await loadConfig();
for (dynamic node in config.keys) {
if (node != 'global')
channelConfig[node.toString()] = new ChannelConfig(
- mods: new List<String>.from(config[node]['mods'] == null ? config['global']['mods'] : config[node]['mods']),
- whitelist: new List<String>.from(config[node]['whitelist'] == null ? config['global']['whitelist'] : config[node]['whitelist']),
- slow_mode: new Map.from(config[node]['slow_mode'] == null ? config['global']['slow_mode'] : config[node]['slow_mode']),
- caps_removal: new Map.from(config[node]['caps_removal'] == null ? config['global']['caps_removal'] : config[node]['caps_removal']),
- block_links: new Map<String, bool>.from(config[node]['block_links'] == null ? config['global']['block_links'] : config[node]['block_links']),
- blacklisted_words: new List<String>.from(config[node]['blacklisted_words'] == null ? config['global']['blacklisted_words'] : config[node]['blacklisted_words']),
- mentions_spam: new Map.from(config[node]['mentions_spam'] == null ? config['global']['mentions_spam'] : config[node]['mentions_spam']),
- repeat_spam: new Map<String, bool>.from(config[node]['repeat_spam'] == null ? config['global']['repeat_spam'] : config[node]['repeat_spam'])
+ mods: new List<String>.from(config[node]['mods'] ?? config['global']['mods']),
+ whitelist: new List<String>.from(config[node]['whitelist'] ?? config['global']['whitelist']),
+ slow_mode: new Map.from(config[node]['slow_mode'] ?? config['global']['slow_mode']),
+ caps_removal: new Map.from(config[node]['caps_removal'] ?? config['global']['caps_removal']),
+ block_links: new Map<String, bool>.from(config[node]['block_links'] ?? config['global']['block_links']),
+ blacklisted_words: new List<String>.from(config[node]['blacklisted_words'] ?? config['global']['blacklisted_words']),
+ mentions_spam: new Map.from(config[node]['mentions_spam'] ?? config['global']['mentions_spam']),
+ repeat_spam: new Map<String, bool>.from(config[node]['repeat_spam'] ?? config['global']['repeat_spam']),
+ welcome: new Map.from(config[node]['welcome'] ?? {'enabled': false})
);
}
@@ -38,12 +39,25 @@ main() async {
bot.onReady.listen(onReady);
bot.onMessage.listen(onMessage);
bot.onMessageUpdate.listen(onMessageUpdate);
+ bot.onGuildMemberAdd.listen(onGuildMemberAdd);
}
onReady(ReadyEvent e) {
print('Ayaka is online!');
}
+onGuildMemberAdd(GuildMemberAddEvent e) {
+ channelConfig.forEach((id, config) {
+ if (config.welcome['enabled'] && e.member.guild.channels.containsKey(id)) {
+ Map replacers = {'user': e.member.username, 'server': e.member.guild.name, 'mention': e.member.mention};
+ bot.channels[id].sendMessage(config.welcome['message'].replaceAllMapped(
+ new RegExp(r"\{(user|server|mention)\}", caseSensitive: false),
+ (Match m) => replacers[m[1]]
+ ));
+ }
+ });
+}
+
onMessage(MessageEvent e) {
if (e.message.channel is DMChannel || !channelConfig.containsKey(e.message.channel.id))
return null;
@@ -322,6 +336,18 @@ registerCommands() {
channelConfig[m.channel.id].repeat_spam['ignore_case'] = args.toLowerCase().contains('ignore case');
};
};
+
+ commands['welcome'] = (Message m, String args) {
+ switch (args.toLowerCase()) {
+ case 'disable':
+ case 'off':
+ channelConfig[m.channel.id].welcome['enabled'] = false;
+ break;
+ default:
+ channelConfig[m.channel.id].welcome['enabled'] = true;
+ channelConfig[m.channel.id].welcome['message'] = args;
+ };
+ };
}
handlePossibleCommand(Message m) {
View
@@ -0,0 +1,47 @@
+[global]
+ token = "ABCDEFgH.IJK_LMNOPQER"
+ prefix = "!"
+ # Users that can use commands (also whitelisted)
+ mods = ["95286900801146880", "125367104336691200"]
+ # Users to not moderate
+ whitelist = ["81440962496172032"]
+ # Stop messages with certain words from being posted (put all words/phrases in lowercase)
+ blacklisted_words = ["kill your self", "faggot"]
+ # Restrict how many messages a user can send
+ [global.slow_mode]
+ enabled = false
+ time = 1000 # Milliseconds between messages (seconds * 1000)
+ # Stop caps spam
+ [global.caps_removal]
+ enabled = false
+ threshold = 10 # Max amount of caps in a row in a message
+ # Stop links from being posted in chat
+ [global.block_links]
+ enabled = false
+ invites_only = false # Only delete discord invites
+ allow_non_embed = true # Allow links wrapped in <> that don"t show a preview
+ # Stop mention spam
+ [global.mentions_spam]
+ enabled = true
+ threshold = 10 # If the message has this many mentions or more
+ action = "kick" # One of: delete, kick, ban
+ # Stop repeat messages
+ [global.repeat_spam]
+ enabled = false
+ ignore_case = true
+
+# Specific channel settings
+[148656206867726336]
+ blacklisted_words = []
+ [148656206867726336.slow_mode]
+ enabled = true
+ time = 5000
+ [148656206867726336.welcome]
+ enabled = true
+ # {user} = their username. {mention} = mention them. {server} = the server's name
+ message = "Welcome to the server {user}!"
+
+[237223871563038720]
+ [237223871563038720.caps_removal]
+ enabled = true
+ threshold = 10
View
@@ -1,41 +0,0 @@
-global:
- token: ABCDEFgH.IJK_LMNOPQER
- prefix: '!'
- # Users that can use commands (also whitelisted)
- mods: ['95286900801146880', '125367104336691200']
- # Users to not moderate
- whitelist: ['81440962496172032']
- # Restrict how many messages a user can send
- slow_mode:
- enabled: false
- time: 1000 # Milliseconds between messages (seconds * 1000)
- # Stop caps spam
- caps_removal:
- enabled: false
- threshold: 10 # Max amount of caps in a row in a message
- # Stop links from being posted in chat
- block_links:
- enabled: false
- invites_only: false # Only delete discord invites
- allow_non_embed: true # Allow links wrapped in <> that don't show a preview
- # Stop messages with certain words from being posted (put all words/phrases in lowercase)
- blacklisted_words: ['kill your self', 'faggot']
- # Stop mention spam
- mentions_spam:
- enabled: true
- threshold: 10 # If the message has this many mentions or more
- action: 'kick' # One of: delete, kick, ban
- # Stop repeat messages
- repeat_spam:
- enabled: false
- ignore_case: true # Ignores capital or lowercase
-# Specific channel settings
-148656206867726336:
- slow_mode:
- enabled: true
- time: 5000
- blacklisted_words: []
-237223871563038720:
- caps_removal:
- enabled: true
- threshold: 10
View
@@ -1,10 +1,10 @@
name: ayaka
description: A chat moderation bot for Discord
-version: 1.0.0
+version: 1.2.0
author: brussell98
dependencies:
discord:
git:
url: git://github.com/Hackzzila/Discord-Dart.git
ref: indev
- yaml:
+ toml: ^0.5.0

0 comments on commit 592750b

Please sign in to comment.