Skip to content

Instantly share code, notes, and snippets.

@tripl3dogdare
Last active June 22, 2019 00:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripl3dogdare/cef2aa316df377945d9391be0ac7b590 to your computer and use it in GitHub Desktop.
Save tripl3dogdare/cef2aa316df377945d9391be0ac7b590 to your computer and use it in GitHub Desktop.
AutoLeaf v0.0.2-ALPHA
require 'discordrb'
require 'hash_dot'; Hash.use_dot_syntax = Hash.hash_dot_use_default = true
require 'json'
include Discordrb
AwaitingJudgement = {}
module AutoLeaf
extend EventContainer
extend Commands::CommandContainer
ready do
log 'Ready!'
Client.playing = 'leaf.info'
end
command :ping do 'Pong!' end
command :info do |e|
e.send_embed {|embed|
embed.title = 'AutoLeaf v0.0.2-ALPHA'
embed.description = <<~info
Immediately bans the following things when a new member joins:
- discord.gg links in name
- "add me SomeName (tag) 1234"
- Instant leavers (after 3 offenses)
Offenders will be banned from all servers AutoLeaf protects, and instant-leavers will be tracked cross-server.
This is not designed to be a permanent solution! This is simply a patch to help slightly alleviate the current issues until Discord gets it figured out.
[Invite to Server](#{Client.invite_url(permission_bits: 18436)})
[Creator's Website](https://bots.tripl3dogdare.com)
[Support Server](http://discord.gg/X73VcaK)
info
embed.color = 0x0da55e
}
end
member_join do |e|
next ban(e) if e.member.username =~ /discord\.gg/
next ban(e) if e.member.username =~ /discord\.me/
next ban(e) if e.member.username =~ /paypal\.me/
next ban(e) if e.member.username =~ /bit\.ly/
next ban(e) if e.member.username =~ /twitch\.tv/
next ban(e) if e.member.username =~ /sekr0\.tk/
next ban(e) if e.member.username =~ /twitter\.com/
next ban(e) if e.member.username =~ /add me .+ ?\(tag\) ?\d{4}/
next ban(e) if e.member.username =~ /pls add .+ ?\(tag\) ?\d{4}/
sleep 5
e.server.delete_member(e.member.id) # Clear member from cache
ban(e, true) unless e.server.member(e.member.id)
end
def self.ban(event, lenient=false)
if lenient
AwaitingJudgement[event.member.id] ||= 0
AwaitingJudgement[event.member.id] += 1
return log "#{event.member.distinct} (#{event.member.id}) has received #{AwaitingJudgement[event.member.id]} auto-leaver offenses" if AwaitingJudgement[event.member.id] < 3
end
Client.servers.each {|_,server|
begin
server.ban(event.member, 1, reason: lenient ? "Repeated auto-leaving offenses across various servers" : "Known advertisement schemes in username")
rescue
log $!.message
end
}
log "Banned #{event.member.distinct} (#{event.member.id}) from #{Client.servers.length} servers"
end
end
def log str
puts str
File.write('latest.log', str+"\n", mode: 'a')
end
Client = Commands::CommandBot.new(
token: File.read('.auth'),
client_id: '475451768403263498',
ignore_bots: true,
help_command: false,
prefix: 'leaf.'
)
Client.set_user_permission(204718116020682753, 999)
Client.include! AutoLeaf
Thread.new do loop do case gets.chomp
when "rs", "restart" then exec "./autoleaf.bat"
when "st", "stop" then Client.stop
when /^sh(?:ell)? (.*)/ then system $1
when /^ev(?:al)? (.*)/ then begin puts eval($1).inspect
rescue Exception => e; puts e.message end
end end end
Client.run
source 'https://rubygems.org'
gem 'discordrb', git: 'https://github.com/meew0/discordrb'
gem 'hash_dot'
@natewu
Copy link

natewu commented Aug 6, 2018

Thanks Tripl3dogdare!

@dedmen
Copy link

dedmen commented Aug 7, 2018

Thanks! Now I can finally autoban all these pls add tripl3dogdare (tag) bots :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment