From ed19b99d9973ac40790e30f193e93f74175cc1a2 Mon Sep 17 00:00:00 2001 From: Nikurasu Date: Sun, 31 Oct 2021 17:40:48 +0100 Subject: [PATCH] FEATURE: Added command to get privacy friendly links --- lib/auth.rb.example | 14 ++++++++++++++ lib/discord-r9k.rb | 29 +++++++++-------------------- lib/messages.db | 6 +++--- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/auth.rb.example b/lib/auth.rb.example index 9dea96f..96ac738 100644 --- a/lib/auth.rb.example +++ b/lib/auth.rb.example @@ -6,3 +6,17 @@ TOKEN = "YOUR_TOKEN_HERE" 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" diff --git a/lib/discord-r9k.rb b/lib/discord-r9k.rb index f4aab3b..72aa9c3 100644 --- a/lib/discord-r9k.rb +++ b/lib/discord-r9k.rb @@ -4,19 +4,9 @@ require 'discordrb' require 'set' require './auth' -bot = Discordrb::Bot.new token: TOKEN +bot = Discordrb::Commands::CommandBot.new token: TOKEN, prefix: PREFIX $messages = Set.new -$messagesWithSocialLink = Set.new - -def freeLinkCreator(event) - msg = event.message.content - $messagesWithSocialLink.each do |platform| - if msg.include? platform then - $messagesWithSocialLink << event.message.id - end - end -end bot.ready do |event| chan = bot.channel CHANNEL @@ -24,8 +14,10 @@ bot.ready do |event| bot.watching = "Messages in #" + chan.name end +def convertLink(link) +end + bot.message do |event| - freeLinkCreator(event) if CHANNELS.include? event.channel.id then if $messages.include? event.content then msg = event.message @@ -38,14 +30,11 @@ bot.message do |event| end end -bot.reaction_add do |event| - if $messagesWithSocialLink.include? event.message.id then - #begin - # TODO: - # [ ] Get Link in message - # [ ] Refactor freeLink freeLinkCreator - # [ ] Make $messagesWithSocialLink unnessecairy - #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 diff --git a/lib/messages.db b/lib/messages.db index 02257ab..63f2ab5 100644 --- a/lib/messages.db +++ b/lib/messages.db @@ -1,5 +1,5 @@ this is a test message this is another test message -this is a third test message -test -https://twitter.com +this is a third test messag +lol +yay