Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored iranzo/stampython #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sourcery-ai-bot
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/stampython master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@sourcery-ai-bot sourcery-ai-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

stampy/env.py Outdated
Comment on lines 49 to 50
# if a database path was provided, override the one in alembic.ini
database = context.get_x_argument(as_dictionary=True).get('database')
if database:
url = "sqlite:///%s" % database
if database := context.get_x_argument(as_dictionary=True).get('database'):
url = f"sqlite:///{database}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run_migrations_offline refactored with the following changes:

This removes the following comments ( why? ):

# if a database path was provided, override the one in alembic.ini

stampy/env.py Outdated
Comment on lines 74 to 73
# if a database path was provided, override the one in alembic.ini
database = context.get_x_argument(as_dictionary=True).get('database')
if database:
ini_section['sqlalchemy.url'] = "sqlite:///%s" % database
if database := context.get_x_argument(as_dictionary=True).get('database'):
ini_section['sqlalchemy.url'] = f"sqlite:///{database}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run_migrations_online refactored with the following changes:

This removes the following comments ( why? ):

# if a database path was provided, override the one in alembic.ini

triggers = []
for each in newplug.init():
triggers.append(each)
triggers = list(newplug.init())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function initplugins refactored with the following changes:

Comment on lines -111 to +115
'-x', 'database=%s' % options.database, '--raiseerr',
'upgrade', 'head',
'-x',
f'database={options.database}',
'--raiseerr',
'upgrade',
'head',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function createorupdatedb refactored with the following changes:

Comment on lines -194 to +200
if "```" in text:
markdown = True
else:
markdown = False

texto = string.join(lines[0:maxlines], "\n")
markdown = "```" in text
texto = string.join(lines[:maxlines], "\n")
if markdown:
texto = "%s```" % texto
texto = f"{texto}```"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sendmessage refactored with the following changes:

stampy/stampy.py Outdated
# If we're not admin and admin is empty, consider ourselves admin
if not admin:
if plugin.config.config(key='admin', gid=chat_id, default="") == "":
if plugin.config.config(key='admin', gid=chat_id, default="") == "":
if not admin:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_owner_or_admin refactored with the following changes:

This removes the following comments ( why? ):

# If we're not admin and admin is empty, consider ourselves admin

stampy/stampy.py Outdated
Comment on lines 943 to 949
if plugin.config.gconfig(key='isolated', default=False, gid=gid):
# Isolated is defined for either channel or general bot config.
# need to check now if group is linked and if so, return that gid,
# and if not, return groupid

link = plugin.config.gconfig(key='link', default=False, gid=gid)
if link:
# This chat_id has 'link' defined against master, effective gid
# should be that one
return int(link)
else:
return gid
else:
if not plugin.config.gconfig(key='isolated', default=False, gid=gid):
# Non isolation configured, returning '0' as gid to use
return 0
if link := plugin.config.gconfig(key='link', default=False, gid=gid):
# This chat_id has 'link' defined against master, effective gid
# should be that one
return int(link)
else:
return gid
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function geteffectivegid refactored with the following changes:

This removes the following comments ( why? ):

# Isolated is defined for either channel or general bot config.
# and if not, return groupid
# need to check now if group is linked and if so, return that gid,

triggers = ["^/admin"]
return triggers
return ["^/admin"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Comment on lines -28 to +27
def run(message): # do not edit this line
def run(message): # do not edit this line
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

Comment on lines 92 to 91
token = texto.split(' ')[3]
if token:
if token := texto.split(' ')[3]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function admincommands refactored with the following changes:

Comment on lines -123 to +122
token = ''.join((random.choice(charset)) for x in range(size))
generatedtoken = "%s:%s" % (chat_id, token)
token = ''.join((random.choice(charset)) for _ in range(size))
generatedtoken = f"{chat_id}:{token}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function changenmastertoken refactored with the following changes:

masterid = stampy.plugin.config.config(key='link', default=False, gid=chat_id)

if masterid:
if masterid := stampy.plugin.config.config(
key='link', default=False, gid=chat_id
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function chanunlink refactored with the following changes:

Comment on lines 245 to 250
masterid = stampy.plugin.config.config(key='link', default=False, gid=chat_id)

if masterid:
if masterid := stampy.plugin.config.config(
key='link', default=False, gid=chat_id
):
# We've a master channel, report it
text = _("This channel %s is slave of channel %s") % (chat_id, masterid)
else:
# We nee to check database to see if we've any slave
sql = "SELECT id from config where key='link' and value='%s'" % chat_id
sql = f"SELECT id from config where key='link' and value='{chat_id}'"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function chanshowslave refactored with the following changes:

triggers = ["^/alias"]
return triggers
return ["^/alias"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Comment on lines -27 to +26
def run(message): # do not edit this line
def run(message): # do not edit this line
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

triggers = ["^/quit"]
return triggers
return ["^/quit"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Comment on lines -24 to +23
def run(message): # do not edit this line
def run(message): # do not edit this line
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

triggers = ["^/cn"]
return triggers
return ["^/cn"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Comment on lines 27 to 32
def run(message): # do not edit this line
def run(message): # do not edit this line
"""
Executes plugin
:param message: message to run against
:return:
"""
text = stampy.stampy.getmsgdetail(message)["text"]
if text:
if text := stampy.stampy.getmsgdetail(message)["text"]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

Comment on lines -40 to +46
def help(message): # do not edit this line
def help(message): # do not edit this line
"""
Returns help for plugin
:param message: message to process
:return: help text
"""
commandtext = _("Use `/cn <word>` to get a random Chuck Norris quote based on word\n\n")
return commandtext
return _(
"Use `/cn <word>` to get a random Chuck Norris quote based on word\n\n"
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function help refactored with the following changes:

Comment on lines -66 to +65
logger.debug(msg=_L("Command: %s by %s" % (texto, who_un)))
logger.debug(msg=_L(f"Command: {texto} by {who_un}"))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function cn refactored with the following changes:

triggers = ["*"]

return triggers
return ["*"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Comment on lines -35 to +33
def run(message): # do not edit this line
def run(message): # do not edit this line
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

Comment on lines -100 to +104
def help(message): # do not edit this line
def help(message): # do not edit this line
"""
Returns help for plugin
:param message: message to process
:return: help text
"""
commandtext = ""
return commandtext
return ""
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function help refactored with the following changes:

triggers.extend(["/%s" % comic])
triggers.extend([f"/{comic}"])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

triggers = ["^/espp"]
return triggers
return ["^/espp"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Comment on lines 27 to 33
def run(message): # do not edit this line
def run(message): # do not edit this line
"""
Executes plugin
:param message: message to run against
:return:
"""
text = stampy.stampy.getmsgdetail(message)["text"]
if text:
if text.split()[0].lower()[0:5] == "/espp":
if text := stampy.stampy.getmsgdetail(message)["text"]:
if text.split()[0].lower()[:5] == "/espp":
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

Comment on lines -40 to +44
def help(message): # do not edit this line
def help(message): # do not edit this line
"""
Returns help for plugin
:param message: message to process
:return: help text
"""
commandtext = _("Use `/espp <amount>` to get estimated ESPP earnings\n\n")
return commandtext
return _("Use `/espp <amount>` to get estimated ESPP earnings\n\n")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function help refactored with the following changes:

Comment on lines 85 to 84
initial = float(stampy.plugin.config.gconfig(key="espp", default=False, gid=chat_id))
if initial:
if initial := float(
stampy.plugin.config.gconfig(key="espp", default=False, gid=chat_id)
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function espp refactored with the following changes:

Comment on lines -32 to +35
triggers = ["^/feed"]

if botname == 'redken_bot':
stampy.stampy.cronme(name="feed", interval=5)

return triggers
return ["^/feed"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants