From 779064a68f45b993d6371de96d6149d5e9b7dac6 Mon Sep 17 00:00:00 2001
From: TheSmallBlue <ilanmori@hotmail.com>
Date: Sun, 20 Dec 2020 16:10:15 -0300
Subject: [PATCH] First commit

---
 launch.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 launch.py

diff --git a/launch.py b/launch.py
new file mode 100644
index 0000000..47c9e56
--- /dev/null
+++ b/launch.py
@@ -0,0 +1,72 @@
+import discord
+import os
+import praw
+import random
+
+from dotenv import load_dotenv
+
+load_dotenv()
+TOKEN = os.getenv('DISCORD_TOKEN')
+SECRET = os.getenv('REDDIT_SECRET')
+
+subreddit = praw.Reddit(client_id='yvXh2hrDELw6eg', \
+                     client_secret=SECRET, \
+                     user_agent='KumikoBot').subreddit('rarekumikos')
+hot_subreddit = subreddit.hot(limit=500)
+
+totalimgs = 0
+posts = []
+authors = []
+posturls = []
+def refresh_posts():
+	print('Refreshing posts!')
+	posts.clear()
+	authors.clear()
+	posturls.clear()
+	global totalimgs
+	totalimgs=0
+	i=0
+	for submission in subreddit.hot(limit=500):
+		#_ = os.system('clear')
+		i = i + 1
+		totalimgs = totalimgs + 1
+		print('Getting submission number '+ str(i) +' / 500!')
+		if ".jpg" not in submission.url and ".png" not in submission.url:
+			print('Post is not a jpg or png (or should be)--------------------------')
+			print(str(submission.url))
+			totalimgs = totalimgs - 1
+			continue
+		posts.append(submission.url)
+		authors.append(submission.author)
+		posturls.append(submission.permalink)
+	print('Total amount of images: '+str(totalimgs))
+
+
+def create_embed(post,author,posturl):
+	embed = discord.Embed(
+		color = discord.Colour.dark_orange()
+		)
+	embed.set_image(url=post)
+	embed.description ='['+str(author)+'](https://www.reddit.com'+str(posturl)+')'
+	return embed
+
+refresh_posts()
+
+client = discord.Client()
+
+@client.event
+async def on_ready():
+	print(f'{client.user} has connected to Discord!')
+
+@client.event
+async def on_message(message):
+	if message.author == client.user:
+		return
+	if "show me a kumiko" in message.content.lower():
+		postnumber = random.randint(1,totalimgs)
+		await message.channel.send(embed = create_embed(posts[postnumber],authors[postnumber],posturls[postnumber]))
+
+	if "refresh the kumikos" in message.content.lower():
+		refresh_posts()
+
+client.run(TOKEN)
\ No newline at end of file
-- 
GitLab