Browse Source

Add b&ops killfile

master
parent
commit
08133cdc10
No known key found for this signature in database GPG Key ID: DA34C790D267C164
7 changed files with 80 additions and 3 deletions
  1. +17
    -0
      .vscode/launch.json
  2. +7
    -1
      .vscode/tasks.json
  3. +1
    -0
      README.md
  4. +1
    -1
      shard.yml
  5. +3
    -1
      src/Bampersand.cr
  6. +5
    -0
      src/commands/ops.cr
  7. +46
    -0
      src/modules/Killfile.cr

+ 17
- 0
.vscode/launch.json View File

@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "gdb",
"request": "launch",
"preLaunchTask": "regular-shards",
"target": "./bin/Bampersand",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
}
]
}

+ 7
- 1
.vscode/tasks.json View File

@ -11,6 +11,12 @@
"kind": "build",
"isDefault": true
}
}
},
{
"label": "regular-shards",
"type": "shell",
"command": "shards build --debug",
"group": "build"
}
]
}

+ 1
- 0
README.md View File

@ -11,6 +11,7 @@ Adapt `.env.example` to your needs and rename it to `.env`. It's gitignored by d
4. `create table slowmodes (channel_id unsigned integer unique on conflict replace, secs unsigned integer);`
5. `create table warnings (guild_id unsigned integer, user_id unsigned integer, mod_id unsigned integer, text string, timestamp date default current_timestamp);`
6. `create table perms (guild_id unsigned integer unique on conflict replace, admin_id unsigned integer, moderator_id unsigned integer);`
7. `create table killfile (guild_id unique on conflict replace);`
## Contributing


+ 1
- 1
shard.yml View File

@ -1,5 +1,5 @@
name: Bampersand
version: 0.15.1
version: 0.16.0
authors:
- deing <admin@15318.de>


+ 3
- 1
src/Bampersand.cr View File

@ -28,6 +28,7 @@ require "./modules/Mirroring"
require "./modules/Board"
require "./modules/JoinLeaveLog"
require "./modules/ModTools"
require "./modules/Killfile"
require "./modules/Commands"
module Bampersand
@ -84,8 +85,9 @@ module Bampersand
end
bot!.on_guild_create do |payload|
LOG.info(
"Joined new guild #{payload.name} — Owner is #{payload.owner_id}"
"Joined new guild #{payload.name} [#{payload.id}] — Owner is #{payload.owner_id}"
)
Killfile.handle_join(payload)
end
bot!.on_guild_member_add do |payload|
JoinLeaveLog.handle_join(payload)


+ 5
- 0
src/commands/ops.cr View File

@ -7,3 +7,8 @@ Commands.register_command("ops rebuild", "Rebuilds Bampersand from the latest so
raise "Build failed" unless system("shards build --release")
"Successfully rebuilt in #{Time.utc_now - ctx.timestamp}."
end
Commands.register_command("ops blacklist", "Adds a guild to the killfile and leaves it.", Perms::Level::Operator) do |args|
Arguments.assert_count(args, 1)
Killfile.add_to_killfile(args[0].to_u64)
true
end

+ 46
- 0
src/modules/Killfile.cr View File

@ -0,0 +1,46 @@
module Killfile
# This module handles guildwide self-blocks.
extend self
@@killfile: Array(UInt64) = load_killfile
def load_killfile
killfile = [] of UInt64
Bampersand::DATABASE.query "select * from killfile" do |rs|
rs.each do
killfile += [rs.read(Int64).to_u64]
end
end
killfile
end
def handle_join(payload)
if @@killfile.includes? payload.id.to_u64
bot!.leave_guild(payload.id)
LOG.info("Guild #{payload.id} is in killfile, leaving again.")
end
end
def add_to_killfile(guild_id)
LOG.info("Adding guild #{guild_id} to killfile.")
@@killfile << guild_id
Bampersand::DATABASE.exec "insert into killfile (guild_id) values (?)", guild_id.to_i64
channels = cache!.channels.values.select { |channel|
(channel.guild_id || 0).to_u64 == guild_id
}
send_success = false
channels.each do |channel|
next if send_success
begin
bot!.create_message(channel.id, "The Bot operator is no longer comfortable with you using their services. This decision is final. Have a nice day.")
send_success = true
rescue e
end
end
LOG.info("Sent goodbye message to #{guild_id}") if send_success
bot!.leave_guild(guild_id)
LOG.info("Left guild #{guild_id}.")
end
LOG.info("Loaded Killfile Module, blocking #{@@killfile.size} guilds.")
end

Loading…
Cancel
Save