FEATURE: clean links of message at specific reaction
This commit is contained in:
parent
ed19b99d99
commit
1a093362de
3 changed files with 107 additions and 92 deletions
|
@ -1,22 +1,22 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
TOKEN = "YOUR_TOKEN_HERE"
|
||||
|
||||
# Channel to bootstrap db form (and to display in status)
|
||||
CHANNEL = 536907792859267083
|
||||
# All channels to watch
|
||||
CHANNELS = [ 536907792859267083, 560880728796168221 ]
|
||||
|
||||
# Specify the alternatives to use
|
||||
ALTPLATFORMS = {
|
||||
"https://twitter.com"=> "https://nitter.net",
|
||||
"https://www.youtube.com" => "https://yewtu.be",
|
||||
"https://youtube.com" => "https://yewtu.be",
|
||||
"https://imgur.com" => "https://imgin.voidnet.tech",
|
||||
"https://www.reddit.com" => "https://teddit.net",
|
||||
"https://reddit.com" => "https://teddit.net",
|
||||
|
||||
}
|
||||
|
||||
# Set the Prefix
|
||||
PREFIX = "r9k"
|
||||
#!/usr/bin/ruby
|
||||
|
||||
TOKEN = "YOUR_TOKEN_HERE"
|
||||
|
||||
# Channel to bootstrap db form (and to display in status)
|
||||
CHANNEL = 536907792859267083
|
||||
# All channels to watch
|
||||
CHANNELS = [ 536907792859267083, 560880728796168221 ]
|
||||
|
||||
# Specify the alternatives to use
|
||||
ALTPLATFORMS = {
|
||||
"https://twitter.com"=> "https://nitter.net",
|
||||
"https://www.youtube.com" => "https://yewtu.be",
|
||||
"https://youtube.com" => "https://yewtu.be",
|
||||
"https://imgur.com" => "https://imgin.voidnet.tech",
|
||||
"https://www.reddit.com" => "https://teddit.net",
|
||||
"https://reddit.com" => "https://teddit.net",
|
||||
|
||||
}
|
||||
|
||||
# Set the Prefix
|
||||
PREFIX = "r9k"
|
||||
|
|
|
@ -1,68 +1,84 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'discordrb'
|
||||
require 'set'
|
||||
require './auth'
|
||||
|
||||
bot = Discordrb::Commands::CommandBot.new token: TOKEN, prefix: PREFIX
|
||||
|
||||
$messages = Set.new
|
||||
|
||||
bot.ready do |event|
|
||||
chan = bot.channel CHANNEL
|
||||
bot.online
|
||||
bot.watching = "Messages in #" + chan.name
|
||||
end
|
||||
|
||||
def convertLink(link)
|
||||
end
|
||||
|
||||
bot.message do |event|
|
||||
if CHANNELS.include? event.channel.id then
|
||||
if $messages.include? event.content then
|
||||
msg = event.message
|
||||
if msg.attachments.length.zero? then
|
||||
msg.delete "r9k"
|
||||
end
|
||||
else
|
||||
$messages << event.content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
bot.command :cleanlink do |event, link|
|
||||
ALTPLATFORMS.each do |platform, alternative|
|
||||
if link.start_with? platform.to_s then
|
||||
return link.gsub(Regexp.new(Regexp.escape(platform)), alternative)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def init_messages
|
||||
msg_count = 0
|
||||
File.foreach("messages.db") do |entry|
|
||||
$messages << entry.chop.gsub("\v", "\n")
|
||||
msg_count += 1
|
||||
end
|
||||
puts "Read #{msg_count.to_s} messages from database"
|
||||
end
|
||||
|
||||
def save_messages
|
||||
File.open("messages.db", "w") do |file|
|
||||
$messages.each do |msg|
|
||||
file.write msg.gsub("\n", "\v") + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Signal.trap("INT") do
|
||||
save_messages
|
||||
exit
|
||||
end
|
||||
Signal.trap("TERM") do
|
||||
save_messages
|
||||
exit
|
||||
end
|
||||
|
||||
init_messages
|
||||
bot.run
|
||||
#!/usr/bin/ruby
|
||||
|
||||
require 'discordrb'
|
||||
require 'set'
|
||||
require './auth'
|
||||
|
||||
bot = Discordrb::Commands::CommandBot.new token: TOKEN, prefix: PREFIX
|
||||
|
||||
$messages = Set.new
|
||||
|
||||
bot.ready do |event|
|
||||
chan = bot.channel CHANNEL
|
||||
bot.online
|
||||
bot.watching = "Messages in #" + chan.name
|
||||
end
|
||||
|
||||
bot.reaction_add do |event|
|
||||
if event.emoji.name == EMOJI
|
||||
cleanlinks = []
|
||||
ALTPLATFORMS.each do |platform, alternative|
|
||||
linkstemp = event.message.content.scan(/(?<=#{platform})\S+/)
|
||||
linkstemp.each do |link|
|
||||
cleanlinks << alternative + link
|
||||
end
|
||||
end
|
||||
if cleanlinks != []
|
||||
message = "Your cleaned links:\n"
|
||||
cleanlinks.each do |link|
|
||||
message += "\n" + link
|
||||
end
|
||||
bot.send_temporary_message(event.channel, message, 60)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
bot.message do |event|
|
||||
if CHANNELS.include? event.channel.id then
|
||||
if $messages.include? event.content then
|
||||
msg = event.message
|
||||
if msg.attachments.length.zero? then
|
||||
msg.delete "r9k"
|
||||
end
|
||||
else
|
||||
$messages << event.content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
bot.command :cleanlink do |event, link|
|
||||
ALTPLATFORMS.each do |platform, alternative|
|
||||
if link.start_with? platform.to_s then
|
||||
return link.gsub(Regexp.new(Regexp.escape(platform)), alternative)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def init_messages
|
||||
msg_count = 0
|
||||
File.foreach("messages.db") do |entry|
|
||||
$messages << entry.chop.gsub("\v", "\n")
|
||||
msg_count += 1
|
||||
end
|
||||
puts "Read #{msg_count.to_s} messages from database"
|
||||
end
|
||||
|
||||
def save_messages
|
||||
File.open("messages.db", "w") do |file|
|
||||
$messages.each do |msg|
|
||||
file.write msg.gsub("\n", "\v") + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Signal.trap("INT") do
|
||||
save_messages
|
||||
exit
|
||||
end
|
||||
Signal.trap("TERM") do
|
||||
save_messages
|
||||
exit
|
||||
end
|
||||
|
||||
init_messages
|
||||
bot.run
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
this is a test message
|
||||
this is another test message
|
||||
this is a third test messag
|
||||
lol
|
||||
yay
|
||||
Hey https://www.youtube.com/watch?v=RhsWlk0yDW4
|
||||
|
|
Loading…
Reference in a new issue