Files
  • main.py
  • alive.py
  • meme.py
  • requirements.txt
main.py
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import discord
from urllib.request import urlopen
import re
import os
import praw
from discord.ext import commands
import time, random
import meme as me
import wolframalpha
import wikipedia as wp
from alive import keep_alive
# discord.py>=0.16.12
TOKEN = os.environ['TOKEN']
WOLFRAM = os.environ['WOLFRAM']
def remove_trash(index: list) -> list:
    if not isinstance(index, list):
        raise TypeError
    index.remove(index[0])
    index.remove(index[1])
    index.remove(index[2])
    try:
        for i in range(39, 116):
            index.remove(index[i])
    except IndexError:
        pass
listotrash = ["pickles", "stars", "potatoes", "fs", "hundred million thousand stars"]
single = ["pickle", "star", "potato", "f", "hundred million thousand stars"]
reddit = praw.Reddit(client_id='FvsbeaJuTBqqvA',
                     client_secret=os.environ['REDDIT_SECRET'],
                     password=os.environ['REDDIT_PASS'],
                     user_agent='testscript by /u/fakebot3',
                     username='pabloitoman')
client = discord.Client()
wolf = wolframalpha.Client(WOLFRAM)
bot = commands.Bot(command_prefix='?', description='A bot that greets the user back.')
bot.remove_command('help')

@bot.command()
async def help(ctx):
    embed = discord.Embed(title="Shrek meme bot thing", description="Very bot. So much nice. List of commands are:", color=0x33bd33)

    embed.add_field(name="?hello", value="Gives a nice greet message", inline=False)
    embed.add_field(name="?meme <meme>", value="Returns given meme information from knowyourmeme.com", inline=False)
    embed.add_field(name="?memereview <literally anything>", value="Returns a rating of anything basically", inline=False)
    embed.add_field(name="?ping", value="Returns ping", inline=False)
    embed.add_field(name="?compute <expression>", value="Solves simple Maths", inline=False)
    embed.add_field(name="?help", value="Gives this message", inline=False)
    embed.add_field(name="?top <subreddit>", value="Takes given subreddit and returns top of all time", inline=False)
    embed.add_field(name="?hot <subreddit>", value="Takes given subreddit and returns hot", inline=False)

    await ctx.send(embed=embed)
    await ctx.send("Any additional support for this bot can be found at @safan41#9134 and @ithinknotdumbo#5355's discord server: https://discord.gg/BAnCs4E")
@bot.command()
async def hello(ctx):
    await ctx.send('Hello {0.author.mention}'.format(ctx))

@bot.command()
async def peepee(ctx):
    await ctx.send('poopoo man')
@bot.group(name="acr", pass_context= True)
async def acr(ctx):
    pass
@acr.command()
async def gfy(ctx):
  await ctx.send('good for you')
@bot.command()
async def ping(ctx):
    await ctx.send(" :ping_pong: Pong! Ping: {}ms".format(round(bot.latency * 1000)))

@bot.command()
async def pls(self, ctx, *, message: str):
    text_channel = await commands.TextChannelConverter.convert(ctx, message)
    msg = '{0.author.mention}\nPlease move this to {1.mention}'.format(ctx, text_channel)
    await ctx.send(msg)

@bot.command()
async def memereview(ctx, *message: str):
    if not message:
        await ctx.send("I need a meme to review")
    else:
        stars = random.randint(0, 5)
        if stars == 0:
            listotrash.remove("hundred million thousand stars")
            trash = random.choice(listotrash)
        elif stars == 1:
            trash = random.choice(single)
        else:
            trash = random.choice(listotrash)
        await ctx.send("I'd rate this meme to be " + str(stars) + " " + str(trash) + " :ok_hand:")
        if stars == 0:
            listotrash.append("hundred million thousand stars")

@bot.command()
async def top(ctx, *, message: str):
    try:
        hot = reddit.subreddit(message).top('all')
        linkd = []
        thelink = []
        finlink = []
        for sub in hot:
            if sub.over18:
                pass
            else:
                linkd.append(sub.shortlink)
        for id in linkd:
            if linkd.index(id) <= 10:
                thelink.append(id + "\n")
        sh = ''.join(thelink)
        finlink.append(sh)
        shs = ''.join(finlink)
        mgs = "Here's what's top of ALL TIME on r/" + message +":\n" + shs
        await ctx.send(mgs)   
    except:
        await ctx.send("The subreddit r/" + message + " doesn't exist.")
@top.error
async def top_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("Please specify a subreddit")

@bot.command()
async def hot(ctx, *, message: str):
    try:
        hot = reddit.subreddit(message).hot()
        linkd = []
        thelink = []
        finlink = []
        for sub in hot:
            linkd.append(sub.shortlink)
        for id in linkd:
            if linkd.index(id) <= 10:
                thelink.append(id + "\n")
        sh = ''.join(thelink)
        finlink.append(sh)
        shs = ''.join(finlink)
        mgs = "Here's what's top of ALL TIME on r/" + message +":\n" + shs
        await ctx.send(mgs)   
    except:
        await ctx.send("The subreddit r/" + message + " doesn't exist.")
@hot.error
async def hot_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("Please specify a subreddit")

@bot.command()
async def alpha(ctx, *, message: str):
    try:
        res = wolf.query(message)
        await ctx.send(next(res.results).text)   
    except:
        await ctx.send("The requested query couldn't be parsed. Please make sure your query makes sense")
@alpha.error
async def alpha_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("Please add a query")

@bot.group(name="wikipedia", pass_context= True)
async def wikipedia(ctx):
    pass
@wikipedia.command()
async def search(ctx, * , message: str):
    if not wp.search(message):
        await ctx.send("No results were found")
    await ctx.send(" ".join(wp.search(message)))
@wikipedia.command()
async def sum(ctx, * , message: str):
    page = wp.page(message)
    if not page:
        await ctx.send("Not a page, try search")
    embed = discord.Embed(title=page.title, color=0x33bd33)
    if page.images:
        embed.set_thumbnail(url=page.images[0])
    embed.description = wp.summary(message, sentences=7)
    embed.set_footer(text=page.url)
    await ctx.send(embed=embed)


@bot.command()
async def meme(ctx, *, message: str):
    link = ["https://knowyourmeme.com/memes/"]
    link.append(message)
    s = ''.join(link)
    data = me.getMemeData(s)
    embed = discord.Embed(title=data.get("name"), color=0x33bd33)
    embed.set_thumbnail(url=data.get("photo"))
    try:
        embed.add_field(name="Status", value=data.get("status"), inline=False)
    except:
        pass
    try:
        embed.add_field(name="Type", value=data.get("type"), inline=False)
    except:
        pass
    try:
        embed.add_field(name="Origin Year", value=data.get("origin_year"), inline=False)
    except:
        pass
    try:
        embed.add_field(name="Origin Place", value=data.get("origin_place"), inline=False)
    except:
        pass
    try: 
        embed.add_field(name="About", value=data.get("about"), inline=False)
    except:
        pass
    try:
        embed.add_field(name="Origin", value=data.get("origin"), inline=False)
    except:
        pass
    
    await ctx.send(embed=embed)

@meme.error
async def meme_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("Please specify a meme")
@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return
    
@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')
keep_alive()
bot.run(TOKEN)
# await client.send_message(message.channel, 'Error - No meme stats found for "' + mymsg + '"') if anything goes worng