-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
160 lines (125 loc) · 6.53 KB
/
Copy pathmain.py
File metadata and controls
160 lines (125 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from bs4 import BeautifulSoup
import os
import random
import discord
import keepmealive
import feedparser
import webbrowser
import json
from dotenv import load_dotenv
funnyordie = feedparser.parse("https://www.funnyordie.com/rss/index.xml")
ninegag = feedparser.parse("http://9gagrss.com/feed/")
memebase = feedparser.parse("https://memebase.cheezburger.com/rss")
redditmeme = feedparser.parse("https://www.reddit.com/r/memes/.rss?format=xml")
ranimes = feedparser.parse("https://www.reddit.com/r/animemes/.rss?format=xml")
theonion = feedparser.parse("http://www.theonion.com/feeds/rss")
warhammmerfortyk = feedparser.parse("http://rss.moddb.com/groups/warhammer-40k-fans-group/images/feed/rss.xml")
redditfortyk = feedparser.parse("https://www.reddit.com/r/Warhammer40kmemes/.rss?format=xml")
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
keepmealive.keep_alive()
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@client.event
async def on_message(message):
#print("received:{}".format(message))
#print("received:{}".format(message.author.name))
#print(" mentions:{}".format(message.mentions))
#print(" client user:{}".format(client.user))
#print("----------------------------")
# if message.author.name == 'ShogunX':
# print("got a message from :{}".format(message.author))
# response = 'Hello there! I KNOW YOU!!!!'
# await message.channel.send(response)
if client.user in message.mentions:
#print("got a message from :{}".format(message.author))
if 'for the emperor!' in message.content or 'emperor grant me memes' in message.content or '40k' in message.content:
random_item = random.choice(redditfortyk.entries)
jsondata = random_item.content
htmlcontent = jsondata[0]['value']
soup = BeautifulSoup(htmlcontent)
thememecontainer = soup.find('span')
thememe = thememecontainer.find('a')
formatted_item = "Title: {} {}".format(random_item.title,thememe['href'])
response = formatted_item
await message.channel.send(response)
elif '40k art' in message.content:
listofentries = warhammmerfortyk.entries
random_item = random.choice(listofentries)
#formatted_item = "Title: {} {}".format(random_item.title,random_item.media_thumbnail)
#formatted_item = "Title: {} {}".format(random_item.link,random_item.media_content[0]['url'])
formatted_item = "{}".format(random_item.link)
response = formatted_item
await message.channel.send(response)
elif 'memebase' in message.content:
listofentries = memebase.entries
random_item = random.choice(listofentries)
formatted_item = "Title: {} {}".format(random_item.title,random_item.media_thumbnail[0]['url'])
response = formatted_item
await message.channel.send(response)
elif 'reddit' in message.content:
random_item = random.choice(redditmeme.entries)
jsondata = random_item.content
htmlcontent = jsondata[0]['value']
soup = BeautifulSoup(htmlcontent)
thememecontainer = soup.find('span')
thememe = thememecontainer.find('a')
formatted_item = "Title: {} {}".format(random_item.title,thememe['href'])
response = formatted_item
await message.channel.send(response)
elif 'animemes' in message.content:
random_item = random.choice(ranimes.entries)
#print("the item:{}".format(random_item))
#print("the contents{}:".format(random_item.content))
jsondata = random_item.content
#print("the json contents{}:".format(jsondata))
#print("actual content: {}".format(jsondata[0]['value']))
htmlcontent = jsondata[0]['value']
soup = BeautifulSoup(htmlcontent)
thememecontainer = soup.find('span')
thememe = thememecontainer.find('a')
formatted_item = "Title: {} {}".format(random_item.title,thememe['href'])
response = formatted_item
await message.channel.send(response)
elif 'onion' in message.content:
random_item = random.choice(theonion.entries)
soup = BeautifulSoup(random_item.description)
tehimage=soup.find('img')
#formatted_item = "Title: {} {} <br/>{}".format(random_item.title,tehimage['src'],random_item.link)
formatted_item = "Title: {} {}".format(random_item.title,random_item.link)
response = formatted_item
await message.channel.send(response)
elif '9gag' in message.content:
random_item = random.choice(ninegag.entries)
soup = BeautifulSoup(random_item.description)
#print('description {}'.format(soup))
if random_item.category == 'video':
tehvid=soup.find('source')
formatted_item = "Title: {} {}".format(random_item.title,tehvid['src'])
elif random_item.category == 'static':
tehimage=soup.find('img')
#print('description {}'.format(soup))
#print('the pic {}'.format(tehimage.src))
formatted_item = "Title: {} {}".format(random_item.title,tehimage['src'])
else:
formatted_item = "Title: {} {}".format(random_item.title,random_item.description)
response = formatted_item
await message.channel.send(response)
elif 'funny or die' in message.content:
random_item = random.choice(funnyordie.entries)
soup = BeautifulSoup(random_item.description)
tehimage=soup.find('img')
formatted_item = "Title: {} {}".format(random_item.title,tehimage['src'])
response = formatted_item
await message.channel.send(response)
elif 'help':
response = "For fresh memes type one of the following: 40k,40k art, memebase,reddit,animemes,onion,9gag,funny or die"
await message.channel.send(response)
else:
response = "Hail to you {}! I live for memes!".format(message.author.name)
await message.channel.send(response)
if message.author == client.user:
return
client.run(TOKEN)