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