Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions serious_bot/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ def register(cls):


def init():
print('INITIALIZING DATABASE AND LOADING MODELS...')
database.initialize(PostgresqlExtDatabase(
'seriousbot_dev',
user='postgres',
port=5432,
autorollback=True))
print("INITIALIZING DATABASE AND LOADING MODELS...")
database.initialize(
PostgresqlExtDatabase(
"seriousbot_dev", user="postgres", port=5432, autorollback=True
)
)

for model in MODELS:
print(f"Looping {model}")
model.create_table(True)

if hasattr(model, 'SQL'):
if hasattr(model, "SQL"):
database.execute_sql(model.SQL)


Expand Down
12 changes: 4 additions & 8 deletions serious_bot/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ class User(BaseModel):
user_rank = SmallIntegerField(default=0)

class Meta:
db_table = 'users'
db_table = "users"

indexes = (
(('id', 'username', 'discriminator'), True),
)
indexes = ((("id", "username", "discriminator"), True),)


@BaseModel.register
Expand All @@ -29,8 +27,6 @@ class Trivia(BaseModel):
points = SmallIntegerField() # Small should be good.. right? :thonk:

class Meta:
db_table = 'trivia'
db_table = "trivia"

indexes = (
(('guild_id', 'user_id'), False),
)
indexes = ((("guild_id", "user_id"), False),)
8 changes: 6 additions & 2 deletions serious_bot/plugins/dyk/didyouknow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import random

PARSERS = [dykparser.DYKParser(), djtechparser.DJTechParser(), dedustparser.DEDustParser()]
PARSERS = [
dykparser.DYKParser(),
djtechparser.DJTechParser(),
dedustparser.DEDustParser(),
]


def grab_fact():
Expand All @@ -14,6 +18,6 @@ def grab_fact():

fact = parser.get_random()
if fact is None:
return ('Failed to grab a fact!', None)
return ("Failed to grab a fact!", None)
else:
return (fact, parser.name)
1 change: 0 additions & 1 deletion serious_bot/plugins/dyk/parsers/baseparser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class BaseParser:

def __init__(self):
self.name = "Unknown"

Expand Down
5 changes: 2 additions & 3 deletions serious_bot/plugins/dyk/parsers/dedustparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@


class DEDustParser(BaseParser):

def __init__(self):
self.name = 'Penrouk'
self.name = "Penrouk"

loaded_file = open('./serious_bot/plugins/dyk/parsers/de_dust.txt', 'r')
loaded_file = open("./serious_bot/plugins/dyk/parsers/de_dust.txt", "r")
self.lines = loaded_file.readlines()
loaded_file.close()

Expand Down
9 changes: 4 additions & 5 deletions serious_bot/plugins/dyk/parsers/djtechparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@


class DJTechParser(BaseParser):

def __init__(self):
self.name = 'DJTech'
self.name = "DJTech"

def get_random(self):
html = requests.get('http://www.djtech.net/humor/shorty_useless_facts.htm').text
html = requests.get("http://www.djtech.net/humor/shorty_useless_facts.htm").text

parser = BeautifulSoup(html, 'html.parser')
parser = BeautifulSoup(html, "html.parser")

text_list = parser.find_all('font', {'style': 'font-size: 11pt'})
text_list = parser.find_all("font", {"style": "font-size: 11pt"})

if len(text_list) > 0:
return random.choice(text_list).text.replace("\n\t\t", "")
Expand Down
7 changes: 3 additions & 4 deletions serious_bot/plugins/dyk/parsers/dykparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@


class DYKParser(BaseParser):

def __init__(self):
self.name = "Did-You-Knows"

def get_random(self):
page = random.randint(1, 50)

html = requests.get(f"http://www.did-you-knows.com/?page={page}").text
parser = BeautifulSoup(html, 'html.parser')
parser = BeautifulSoup(html, "html.parser")

text_list = parser.find_all('span', {'class': 'dykText'})
text_list = parser.find_all("span", {"class": "dykText"})

if len(text_list) > 0:
return 'Did you know ' + random.choice(text_list).text
return "Did you know " + random.choice(text_list).text
else:
return None
25 changes: 15 additions & 10 deletions serious_bot/plugins/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@


class EventsPlugin(Plugin):

def load(self, ctx):
super(EventsPlugin, self).load(ctx)
self._servers = ctx.get('servers', {})
self._servers = ctx.get("servers", {})

def unload(self, ctx):
ctx['servers'] = self._servers
ctx["servers"] = self._servers
super(EventsPlugin, self).unload(ctx)

@Plugin.listen('MessageCreate')
@Plugin.listen("MessageCreate")
def on_message_create(self, event):
self.log.info(u'{}: {}'.format(event.author, event.content))
self.log.info(u"{}: {}".format(event.author, event.content))

for key, attachment in event.attachments.items():
self.log.info(u'{}, {}, {}'.format(attachment.filename, attachment.url, attachment.proxy_url))
self.log.info(
u"{}, {}, {}".format(
attachment.filename, attachment.url, attachment.proxy_url
)
)

@Plugin.listen('PresenceUpdate')
@Plugin.listen("PresenceUpdate")
def on_presence_update(self, event):
self.log.info(u'Update in {} -> {}'.format(event.guild_id, event.presence.user))
self.log.info(u"Update in {} -> {}".format(event.guild_id, event.presence.user))

@Plugin.listen('Ready')
@Plugin.listen("Ready")
def on_ready(self, event):
self.client.update_presence(Status.online, Game(type=GameType.watching, name='you fail at life.'))
self.client.update_presence(
Status.online, Game(type=GameType.watching, name="you fail at life.")
)
30 changes: 17 additions & 13 deletions serious_bot/plugins/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@


class FunPlugin(Plugin):

def load(self, ctx):
self.roaster = Roast()
self.reddit = Reddit('dankmemes')
self.reddit = Reddit("dankmemes")

# Just scrape them right off the bat and get it over with
# TODO: Sync them every now and then?
Expand All @@ -36,7 +35,7 @@ def on_pre_command(self, command, event, _par, _brack):

return event

@Plugin.command('dyk')
@Plugin.command("dyk")
def on_dyk(self, event):
self.client.api.channels_typing(event.msg.channel_id)

Expand All @@ -46,51 +45,56 @@ def on_dyk(self, event):
embed.description = f"**{fact}**"
embed.set_footer(text=name)
embed.timestamp = datetime.utcnow().isoformat()
embed.color = '10038562'
embed.color = "10038562"

event.msg.reply(embed=embed)

@Plugin.command('urban', '[phrase:str...]')
@Plugin.command("urban", "[phrase:str...]")
def on_urban(self, event, phrase=None):
self.client.api.channels_typing(event.msg.channel_id)

urban_entry = None

if phrase is None:
urban_entry = random.choice(ud.random()) # grab some random words | list of urbandef
urban_entry = random.choice(
ud.random()
) # grab some random words | list of urbandef
else:
defs = ud.define(phrase)

if len(defs) > 0:
urban_entry = defs[0]

if urban_entry is None:
event.msg.reply('Failed to find a definition for that!')
event.msg.reply("Failed to find a definition for that!")
else:
definition = urban_entry.definition
# Let's do a little... checking!
if len(definition) >= 2000:
definition = definition[:1950] + '...'
definition = definition[:1950] + "..."

# Let's construct an embed :)
embed = MessageEmbed()
embed.title = f"**Defintion of {urban_entry.word}**"
embed.description = definition

embed.add_field(name='Example', value=urban_entry.example)
embed.add_field(name='Rating', value=f"{urban_entry.upvotes} 👍 | {urban_entry.downvotes} 👎")
embed.add_field(name="Example", value=urban_entry.example)
embed.add_field(
name="Rating",
value=f"{urban_entry.upvotes} 👍 | {urban_entry.downvotes} 👎",
)

embed.color = '5824574'
embed.color = "5824574"

event.msg.reply(embed=embed)

@Plugin.command('roast')
@Plugin.command("roast")
def on_roast(self, event):
roast = self.roaster.get_random()

event.msg.reply(f"{event.author.mention}, {roast}")

@Plugin.command('meme')
@Plugin.command("meme")
def on_reddit(self, event):
random_post = self.reddit.random_post(self.memes)

Expand Down
Loading