-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
125 lines (93 loc) · 3.33 KB
/
app.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
# MUST BE PYTHON 3.6!!!
import discord
import asyncio
import os
import random
from discord.ext import commands
import markov
# You must have this set to a valid discord bot secret!
# Note windows can be slow/sucky so if may not work immediately :/
TOKEN = os.environ.get('DISCORD_BOT_SECRET')
prefix = "!rip "
default_configs = {"dadword": "dad"}
servers = {}
configs = {"dadword": "dad"}
bot = commands.Bot(command_prefix=prefix, help_command=None)
async def is_mod(ctx):
return ctx.message.author.permissions_in(ctx.message.channel).manage_guild
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Game(name='Advanced Fun'))
@bot.command()
async def thanos(ctx):
names = [member.name for member in ctx.guild.members]
random.shuffle(names)
last = names[int(len(names)/2) - 1]
names = names[0:int(len(names)/2) - 1]
output = ", ".join(names)
if len(names) == 0:
output = last + " has been snapped!"
elif len(names) == 1:
output = ", ".join(names) + " and " + last + " have been snapped!"
elif len(names) > 1:
output = ", ".join(names) + ", and " + last + " have been snapped!"
await ctx.send(output)
@bot.command()
async def generate(ctx):
await ctx.send(markov.generate())
@bot.command()
async def help(ctx):
embed = discord.Embed(title="Ripbot", url="https://www.google.com", description="An almost entertaining bot.",
color=0xffffff)
embed.set_author(name="Ripbot-Help")
embed.add_field(name="Commands", value="thanos, generate", inline=False)
embed.add_field(name="Passive", value="Dad Responses, Markov Builder", inline=False)
embed.set_footer(text="(Check it out on Github)")
await ctx.send(embed=embed)
@bot.group()
@commands.check(is_mod)
async def config(ctx):
if ctx.invoked_subcommand is None:
await ctx.send("No command sent...")
@config.error
async def config_error(ctx, error):
if commands.CheckFailure:
await ctx.send("You don't have the permissions to use that command!")
@config.command()
async def thanos(ctx):
await ctx.send("Thanos snaps half of the members in the server.")
@config.command()
async def setvalue(ctx, arg1, *, args):
if arg1 in configs:
configs[arg1] = args
await ctx.send("Config successfully changed: " + arg1 + " -> " + args)
else:
await ctx.send("Could not find specified config.")
@bot.event
async def on_message(message):
# Ignore bot messages
if message.author.bot:
return
elif message.content.startswith(prefix):
# Check for bot prefix, run command suite if present
await bot.process_commands(message)
else:
checks = ["i'm", "im", "I'm", "IM", "i am", "I am", "I AM"]
dad_out = ""
can_dad = False
# Markov storage
prevword = None
for word in message.content.split():
if can_dad:
dad_out += word + " "
for term in checks:
if term == word:
can_dad = True
dad_out = ""
markov.add_word(prevword, word)
prevword = word
markov.add_word(prevword, None)
if dad_out:
dad_joke = dad_out[:-1]
await message.channel.send("Hi '" + dad_joke + "', I'm " + configs["dadword"] + ".")
bot.run(TOKEN)