Skip to content

Instantly share code, notes, and snippets.

@twnlink
Last active August 31, 2019 23:44
Show Gist options
  • Save twnlink/c565b5d14ac6dc764446320c69aae147 to your computer and use it in GitHub Desktop.
Save twnlink/c565b5d14ac6dc764446320c69aae147 to your computer and use it in GitHub Desktop.
A Discord bot for assisting in Reddit ARGs.
import praw
import discord
import aiohttp
import asyncio
from discord.ext import commands
from prawcore import NotFound
from praw.models import Message
reddit = praw.Reddit(YOU EVER JUST "AAAAAAAAAA"?)
bot = commands.Bot(command_prefix='kd!', description="A bot for understanding the path of Kairos..")
bot.remove_command("help")
@bot.event
async def on_ready():
print('------\nLogged in as:')
print(bot.user.name)
print("With the ID: %s\n------" % bot.user.id)
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="everything... | kd!help"))
@bot.command()
async def help(ctx):
await bot.get_user(ctx.author.id).send('''```
KairosDetective: A Discord bot to assist in solving Reddit ARGs.
kd!url | url is a command used to test TinyURLs to see if
they're valid.
ex: kd!testurl url
kd!solve | solve is a command used to message the moderators of
the current April fool's subreddit.
ex: kd!solve the answer is 5, probably!
kd!suggest | suggest is a command used to suggest new bot ideas
to Satan who will spend hours making them because he's a NEET.
ex: kd!suggest yo you should make the bot solve the arg for us
Thanks for using KairosDetective!
KairosDetective is powered by Swarm black magic and Python.
```
The source code for KairosDetective can be found at: <https://i-am.a-virg.in/kdsource>
<@192760945766957066> is the person responsible for this majestic beautiful bot, throw all of your complaints at him.''')
await ctx.send(f'A list of commands has been sent to your dms <@{ctx.author.id}>.')
@bot.command()
async def solve(ctx, *, solution = None):
if solution == None:
await ctx.send("No message provided, message not sent.")
elif "spam" in solution.lower():
await ctx.send("The word 'spam' is blocked due to Reddit's auto help system picking it up. Sorry :(")
else:
try:
reddit.subreddit('thepathofkairos').message(f'{ctx.author} ({ctx.author.id})', solution)
await ctx.send("Solution sent!\nCheck r/ThePathOfKairos look for a subreddit description update to see if it was correct!")
except:
await ctx.send("ERROR: Something went wrong, I'm not sure what though...")
@bot.command()
async def url(ctx, *, urlpart = None):
if urlpart == None:
await ctx.send("It seems like you didn't provide a shortened URL part to test.\n Please provide one")
else:
if urlpart.isalnum():
async with aiohttp.ClientSession() as session:
async with session.get(f'https://tinyurl.com/{urlpart}', allow_redirects = False) as response:
if response.status != 404 and response.status != 200:
redirecturl = str(response).split("Location': \'")[1].split("\'")[0]
await ctx.send(f'<https://tinyurl.com/{urlpart}> -> <{redirecturl}>')
else:
await ctx.send("That URL seems to be a dud, sorry :(")
else:
await ctx.send("Your URL provided a non alphanumeric character.\nPlease remove that character and try again.")
@bot.command()
async def snipe(ctx, *, subtitle = None):
if ctx.author.id == 192760945766957066 or ctx.author.id == 412782876304867329 or ctx.author.id == 252509640774909952 or ctx.author.id == 413516816137322506:
if subtitle == None:
await ctx.send("It seems like you did not provide a name for the subreddit you would like to snipe.\nPlease try again with a subreddit name provided.")
else:
subtitle = subtitle.replace(' ', '')
if subtitle.isalnum():
if len(subtitle) < 3 or len(subtitle) > 21:
await ctx.send("Your subreddit title was either too short or too long.\nPlease use 3-21 characters in your subreddit name.")
else:
subexists = True
try:
reddit.subreddits.search_by_name(subtitle, exact = True)
except NotFound:
subexists = False
if subexists == False:
try:
reddit.subreddit.create(subtitle, title = subtitle, link_type = 'any', subreddit_type='private')
await ctx.send(f'https://reddit.com/r/{subtitle} has been created! It will be opened when the event is open.')
except:
await ctx.send("ERROR: Something went wrong, I'm not sure what though...")
else:
await ctx.send("It seems that subreddit already exists, sorry.")
else:
await ctx.send("Your subreddit name provided a non alphanumeric character.\nPlease remove that character and try again.")
elif ctx.author.id == 229592588527599616:
# this was specifically made for ilm, someone abusing the snipe command
await ctx.send("I get that you're trying your best to vent your anger but this is dumb. Stop it.")
await bot.get_user(192760945766957066).send(f'ilm tried to abuse me, here\'s the subreddit he tried to make: {subtitle}')
else:
await ctx.send("You don't have permission to do this command, sorry!")
@bot.command()
async def suggest(ctx, *, suggestion):
await bot.get_user(192760945766957066).send(f'{ctx.author} ({ctx.author.id}) has suggested:')
await bot.get_user(192760945766957066).send(suggestion)
await ctx.send('Your suggestion has been sent!')
@bot.command()
async def checkpm(ctx):
msg_count = 0
for item in reddit.inbox.unread(limit=None):
if isinstance(item, Message):
if item.author == None:
author_print = 'Sub mods'
else:
author_print = item.author
msg = (f'```---\nAuthor: {reddit.inbox.message(item.parent_id[3:]).subject}\nMessage: {reddit.inbox.message(item.parent_id[3:]).body}\n---\nFrom: {author_print}\nSubject: {item.body}```')
msg_count += 1
await ctx.send(msg)
item.mark_read()
if msg_count == 0:
msg = "Sorry, inbox is empty..."
await ctx.send(msg)
bot.run('HAHA NO LMAO')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment