Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
Clean up long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Jun 29, 2019
1 parent 86bfc05 commit 5bd5590
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 38 deletions.
16 changes: 11 additions & 5 deletions cloudbot/clients/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ def cmd(self, command, *params):
:type command: str
:type params: (str)
"""
params = [str(param) for param in params] # turn the tuple of parameters into a list
# turn the tuple of parameters into a list
params = [str(param) for param in params]
self.send(str(Message(None, None, command, params)))

def send(self, line, log=True):
Expand Down Expand Up @@ -440,7 +441,10 @@ def get_channel(message: Message):
if command == "INVITE":
return command_params[1]

if len(command_params) > 2 or not (command_params.has_trail and len(command_params) == 1):
if len(command_params) > 2:
return command_params[0]

if not (command_params.has_trail and len(command_params) == 1):
return command_params[0]

return None
Expand Down Expand Up @@ -529,9 +533,11 @@ def handle_line(self, message: Message):
# Set up parsed message
# TODO: Do we really want to send the raw `prefix` and `command_params` here?
event = Event(
bot=self.bot, conn=self.conn, event_type=event_type, content_raw=content_raw, content=content,
target=target, channel=channel, nick=nick, user=user, host=host, mask=mask, irc_raw=str(message),
irc_prefix=mask, irc_command=command, irc_paramlist=command_params, irc_ctcp_text=ctcp_text
bot=self.bot, conn=self.conn, event_type=event_type,
content_raw=content_raw, content=content, target=target,
channel=channel, nick=nick, user=user, host=host, mask=mask,
irc_raw=str(message), irc_prefix=mask, irc_command=command,
irc_paramlist=command_params, irc_ctcp_text=ctcp_text
)

# handle the message, async
Expand Down
14 changes: 8 additions & 6 deletions cloudbot/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,16 @@ async def create_tables(self, bot):
:type bot: cloudbot.bot.CloudBot
"""
if self.tables:
# if there are any tables
if not self.tables:
return

logger.info("Registering tables for %s", self.title)
# if there are any tables

for table in self.tables:
if not await bot.loop.run_in_executor(None, table.exists, bot.db_engine):
await bot.loop.run_in_executor(None, table.create, bot.db_engine)
logger.info("Registering tables for %s", self.title)

for table in self.tables:
if not await bot.loop.run_in_executor(None, table.exists, bot.db_engine):
await bot.loop.run_in_executor(None, table.create, bot.db_engine)

def unregister_tables(self, bot):
"""
Expand Down
3 changes: 2 additions & 1 deletion cloudbot/util/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class Shortener:
def __init__(self):
pass

def shorten(self, url, custom=None, key=None): # pylint: disable=unused-argument,no-self-use
# pylint: disable=unused-argument,no-self-use
def shorten(self, url, custom=None, key=None):
return url

def try_shorten(self, url, custom=None, key=None):
Expand Down
35 changes: 25 additions & 10 deletions plugins/duckhunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,16 @@ def duck_merge(text, conn, db, message):
# TODO: Call dbupdate() and db_add_entry for the items in duckmerge

for channel in channelkey["insert"]:
dbadd_entry(newnick, channel, db, conn, duckmerge[channel]["shot"], duckmerge[channel]["befriend"])
dbadd_entry(
newnick, channel, db, conn,
duckmerge[channel]["shot"], duckmerge[channel]["befriend"]
)

for channel in channelkey["update"]:
dbupdate(newnick, channel, db, conn, duckmerge[channel]["shot"], duckmerge[channel]["befriend"])
dbupdate(
newnick, channel, db, conn,
duckmerge[channel]["shot"], duckmerge[channel]["befriend"]
)

query = table.delete().where(
and_(table.c.network == conn.name, table.c.name == oldnick)
Expand All @@ -875,7 +881,8 @@ def duck_merge(text, conn, db, message):
db.execute(query)
db.commit()
message("Migrated {} and {} from {} to {}".format(
pluralize_auto(duckmerge["TKILLS"], "duck kill"), pluralize_auto(duckmerge["TFRIENDS"], "duck friend"),
pluralize_auto(duckmerge["TKILLS"], "duck kill"),
pluralize_auto(duckmerge["TFRIENDS"], "duck friend"),
oldnick, newnick
))

Expand Down Expand Up @@ -928,7 +935,8 @@ def ducks_user(text, nick, chan, conn, db, message):
# Check if the user has only participated in the hunt in this channel
if ducks["chans"] == 1 and has_hunted_in_chan:
message("{} has killed {} and befriended {} in {}.".format(
name, pluralize_auto(ducks["chankilled"], "duck"), pluralize_auto(ducks["chanfriends"], "duck"), chan
name, pluralize_auto(ducks["chankilled"], "duck"),
pluralize_auto(ducks["chanfriends"], "duck"), chan
))
return None

Expand All @@ -938,10 +946,13 @@ def ducks_user(text, nick, chan, conn, db, message):
"\x02{}'s\x02 duck stats: \x02{}\x02 killed and \x02{}\x02 befriended in {}. "
"Across {}: \x02{}\x02 killed and \x02{}\x02 befriended. "
"Averaging \x02{}\x02 and \x02{}\x02 per channel.".format(
name, pluralize_auto(ducks["chankilled"], "duck"), pluralize_auto(ducks["chanfriends"], "duck"),
name, pluralize_auto(ducks["chankilled"], "duck"),
pluralize_auto(ducks["chanfriends"], "duck"),
chan, pluralize_auto(ducks["chans"], "channel"),
pluralize_auto(ducks["killed"], "duck"), pluralize_auto(ducks["friend"], "duck"),
pluralize_auto(kill_average, "kill"), pluralize_auto(friend_average, "friend")
pluralize_auto(ducks["killed"], "duck"),
pluralize_auto(ducks["friend"], "duck"),
pluralize_auto(kill_average, "kill"),
pluralize_auto(friend_average, "friend")
)
)
return None
Expand Down Expand Up @@ -980,13 +991,17 @@ def duck_stats(chan, conn, db, message):

ducks["chans"] = int((len(ducks["friendchan"]) + len(ducks["killchan"])) / 2)

killerchan, killscore = sorted(ducks["killchan"].items(), key=operator.itemgetter(1), reverse=True)[0]
friendchan, friendscore = sorted(ducks["friendchan"].items(), key=operator.itemgetter(1), reverse=True)[0]
def max_score(data):
return max(data, key=operator.itemgetter(1))

killerchan, killscore = max_score(ducks["killchan"].items())
friendchan, friendscore = max_score(ducks["friendchan"].items())
message(
"\x02Duck Stats:\x02 {:,} killed and {:,} befriended in \x02{}\x02. "
"Across {} \x02{:,}\x02 ducks have been killed and \x02{:,}\x02 befriended. "
"\x02Top Channels:\x02 \x02{}\x02 with {} and \x02{}\x02 with {}".format(
ducks["chankilled"], ducks["chanfriends"], chan, pluralize_auto(ducks["chans"], "channel"),
ducks["chankilled"], ducks["chanfriends"], chan,
pluralize_auto(ducks["chans"], "channel"),
ducks["killed"], ducks["friend"],
killerchan, pluralize_auto(killscore, "kill"),
friendchan, pluralize_auto(friendscore, "friend")
Expand Down
11 changes: 8 additions & 3 deletions plugins/herald.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from collections import defaultdict

from sqlalchemy import Table, Column, String, PrimaryKeyConstraint
from sqlalchemy import Column, PrimaryKeyConstraint, String, Table, and_

from cloudbot import hook
from cloudbot.util import database
Expand Down Expand Up @@ -59,10 +59,15 @@ def herald(text, nick, chan, db, reply):
return None

res = db.execute(
table.update().where(table.c.name == nick.lower()).where(table.c.chan == chan.lower()).values(quote=text)
table.update().where(and_(
table.c.name == nick.lower(),
table.c.chan == chan.lower(),
)).values(quote=text)
)
if res.rowcount == 0:
db.execute(table.insert().values(name=nick.lower(), chan=chan.lower(), quote=text))
db.execute(table.insert().values(
name=nick.lower(), chan=chan.lower(), quote=text
))

db.commit()
reply("greeting successfully added")
Expand Down
21 changes: 15 additions & 6 deletions plugins/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from cloudbot import hook
from cloudbot.util import database
from cloudbot.util.pager import paginated_list, CommandPager
from cloudbot.util.pager import CommandPager, paginated_list

category_re = r"[A-Za-z0-9]+"
data_re = re.compile(r"({})\s(.+)".format(category_re))
Expand Down Expand Up @@ -112,7 +112,8 @@ def profile(text, chan, notice, nick):
category = unpck.pop(0)
cat_cf = category.casefold()
if cat_cf not in user_profile:
notice("User {} has no profile data for category {} in this channel".format(pnick, category))
notice("User {} has no profile data "
"for category {} in this channel".format(pnick, category))
return None

content = user_profile[cat_cf]
Expand All @@ -136,14 +137,22 @@ def profileadd(text, chan, nick, notice, db):
cat, data = match.groups()
if cat.casefold() not in user_profile:
db.execute(
table.insert().values(chan=chan.casefold(), nick=nick.casefold(), category=cat.casefold(), text=data))
table.insert().values(
chan=chan.casefold(), nick=nick.casefold(),
category=cat.casefold(), text=data
)
)
db.commit()
load_cache(db)
return "Created new profile category {}".format(cat)

db.execute(table.update().values(text=data).where((and_(table.c.nick == nick.casefold(),
table.c.chan == chan.casefold(),
table.c.category == cat.casefold()))))
clause = and_(
table.c.nick == nick.casefold(),
table.c.chan == chan.casefold(),
table.c.category == cat.casefold()
)

db.execute(table.update().values(text=data).where(clause))
db.commit()
load_cache(db)
return "Updated profile category {}".format(cat)
Expand Down
4 changes: 2 additions & 2 deletions plugins/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def pympler_diff():

# # Provide an easy way to get a threaddump, by using SIGUSR1 (only on POSIX systems)
if os.name == "posix":
# The handler is called with two arguments: the signal number and the current stack frame
# The handler is called with two arguments:
# the signal number and the current stack frame
# These parameters should NOT be removed
# noinspection PyUnusedLocal
def debug_cb(sig, frame):
print(get_thread_dump())


signal.signal(signal.SIGUSR1, debug_cb) # Register handler
6 changes: 5 additions & 1 deletion plugins/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def get_quote_num(num, count, name):
if num and num < 0: # Count back if possible
num = count + num + 1 if num + count > -1 else count + 1
if num and num > count: # If there are not enough quotes, raise an error
raise QuoteLookupError("I only have {} quote{} for {}.".format(count, ('s', '')[count == 1], name))
raise QuoteLookupError(
"I only have {} quote{} for {}.".format(
count, ('s', '')[count == 1], name
)
)
if num and num == 0: # If the number is zero, set it to one
num = 1
if not num: # If a number is not given, select a random one
Expand Down
4 changes: 3 additions & 1 deletion plugins/remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ async def add_reminder(async_call, db, network, added_user, added_chan, message,
async def load_cache(async_call, db):
new_cache = []

for network, remind_time, added_time, user, message in await async_call(_load_cache_db, db):
data = await async_call(_load_cache_db, db)

for network, remind_time, added_time, user, message in data:
new_cache.append((network, remind_time, added_time, user, message))

reminder_cache.clear()
Expand Down
5 changes: 3 additions & 2 deletions plugins/steamdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def get_data(user, currency="us"):
if cfscrape:
raise SteamError("Could not get user info: {}".format(e))

raise SteamError("Could not get user info: {} (You may have been blocked by CloudFlare, try installing the "
"cfscrape module)".format(e))
raise SteamError("Could not get user info: {} "
"(You may have been blocked by CloudFlare, "
"try installing the cfscrape module)".format(e))

# parse that page!
soup = parse_soup(request.content)
Expand Down
3 changes: 2 additions & 1 deletion tests/core_tests/test_plugin_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@


class MockConfig(OrderedDict):
def get_api_key(self, name, default=None): # pylint: disable=no-self-use, unused-argument
# pylint: disable=no-self-use, unused-argument
def get_api_key(self, name, default=None):
return default # pragma: no cover


Expand Down

0 comments on commit 5bd5590

Please sign in to comment.