Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Sourcery refactored main branch #3

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

Sourcery refactored main branch #3

wants to merge 2 commits into from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 2, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

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

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

Copy link
Author

@sourcery-ai 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.

Comment on lines -133 to +136
sw = spamwatch.Client(spamwatch_api)
return sw
return spamwatch.Client(spamwatch_api)
except:
sw = None
log.warning("Can't connect to SpamWatch!")
return sw
return None
Copy link
Author

Choose a reason for hiding this comment

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

Function KyosukeINIT.init_sw refactored with the following changes:

Comment on lines -273 to +271
apps = []
apps.append(pbot)
apps = [pbot]
Copy link
Author

Choose a reason for hiding this comment

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

Lines 273-274 refactored with the following changes:

imported_module = importlib.import_module("kyosuke.modules." + module_name)
imported_module = importlib.import_module(f"kyosuke.modules.{module_name}")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 87-87 refactored with the following changes:

Comment on lines -172 to +173
url="t.me/{}?startgroup=true".format(
context.bot.username
),
),
url=f"t.me/{context.bot.username}?startgroup=true",
)
Copy link
Author

Choose a reason for hiding this comment

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

Function start refactored with the following changes:

Comment on lines -300 to +302
module = mod_match.group(1)
module = mod_match[1]
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_button refactored with the following changes:

args["pattern"] = "(?i)" + pattern
args["pattern"] = f"(?i){pattern}"
Copy link
Author

Choose a reason for hiding this comment

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

Function inlinequery refactored with the following changes:

args["pattern"] = "(?i)" + pattern
args["pattern"] = f"(?i){pattern}"
Copy link
Author

Choose a reason for hiding this comment

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

Function bot refactored with the following changes:

Comment on lines -152 to +150
unsafe_pattern = r"^[^/!#@\$A-Za-z]"
group_only = args.get("group_only", False)
disable_errors = args.get("disable_errors", False)
insecure = args.get("insecure", False)
if pattern is not None and not pattern.startswith("(?i)"):
args["pattern"] = "(?i)" + pattern
args["pattern"] = f"(?i){pattern}"
Copy link
Author

Choose a reason for hiding this comment

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

Function kyosuke refactored with the following changes:

if not obj:
return False
string = codecs.encode(pickle.dumps(obj), "base64").decode()
return string
return codecs.encode(pickle.dumps(obj), "base64").decode() if obj else False
Copy link
Author

Choose a reason for hiding this comment

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

Function obj_to_str refactored with the following changes:

Comment on lines -45 to +42
obj = pickle.loads(codecs.decode(string.encode(), "base64"))
return obj
return pickle.loads(codecs.decode(string.encode(), "base64"))
Copy link
Author

Choose a reason for hiding this comment

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

Function str_to_obj refactored with the following changes:

Comment on lines -64 to +60
if not _notes:
return {}
return _notes["notes"]
return {} if not _notes else _notes["notes"]
Copy link
Author

Choose a reason for hiding this comment

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

Function _get_notes refactored with the following changes:

Comment on lines -70 to +64
_notes = []
for note in await _get_notes(chat_id):
_notes.append(note)
return _notes
return list(await _get_notes(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 get_note_names refactored with the following changes:

Comment on lines -79 to +70
if name in _notes:
return _notes[name]
return False
return _notes[name] if name in _notes else False
Copy link
Author

Choose a reason for hiding this comment

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

Function get_note refactored with the following changes:

Comment on lines -126 to +115
if not _filters:
return {}
return _filters["filters"]
return {} if not _filters else _filters["filters"]
Copy link
Author

Choose a reason for hiding this comment

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

Function _get_filters refactored with the following changes:

Comment on lines -132 to +119
_filters = []
for _filter in await _get_filters(chat_id):
_filters.append(_filter)
return _filters
return list(await _get_filters(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 get_filters_names refactored with the following changes:

Comment on lines -341 to +308
if not chats:
return []
chats_list = []
for chat in await chats.to_list(length=1000000000):
chats_list.append(chat)
return chats_list
return [] if not chats else list(await chats.to_list(length=1000000000))
Copy link
Author

Choose a reason for hiding this comment

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

Function get_served_chats refactored with the following changes:

Comment on lines -365 to +327
if not user:
return False
return True
return bool(user)
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_served_user refactored with the following changes:

Comment on lines -372 to +332
if not users:
return []
users_list = []
for user in await users.to_list(length=1000000000):
users_list.append(user)
return users_list
return [] if not users else list(await users.to_list(length=1000000000))
Copy link
Author

Choose a reason for hiding this comment

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

Function get_served_users refactored with the following changes:

Comment on lines -395 to +350
if not user:
return False
return True
return bool(user)
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_gbanned_user refactored with the following changes:

Comment on lines -416 to +369
if not lovers:
return {}
return lovers["couple"]
return {} if not lovers else lovers["couple"]
Copy link
Author

Choose a reason for hiding this comment

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

Function _get_lovers refactored with the following changes:

Comment on lines -423 to +374
if date in lovers:
return lovers[date]
return False
return lovers[date] if date in lovers else False
Copy link
Author

Choose a reason for hiding this comment

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

Function get_couple refactored with the following changes:

Comment on lines -440 to +389
if not chat:
return True
return False
return not chat
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_captcha_on refactored with the following changes:

Comment on lines -476 to +423
if not chat:
return True
return False
return not chat
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_antiservice_on refactored with the following changes:

Comment on lines -497 to +442
if not user:
return False
return True
return bool(user)
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_pmpermit_approved refactored with the following changes:

Comment on lines -518 to +461
if not text:
return ""
return text["text"]
return "" if not text else text["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 get_welcome refactored with the following changes:

@rencmd(command="promote", pass_args=True)
@rencmd(command="promote", pass_args=True)
Copy link
Author

Choose a reason for hiding this comment

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

Function promote refactored with the following changes:

Comment on lines 289 to 282
log_message = (
f"<b>{html.escape(chat.title)}:</b>\n"
f"#LOWPROMOTED\n"
f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
f"<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
)

return log_message
return f"<b>{html.escape(chat.title)}:</b>\n#LOWPROMOTED\n<b>Admin:</b> {mention_html(user.id, user.first_name)}\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
Copy link
Author

Choose a reason for hiding this comment

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

Function lowpromote refactored with the following changes:

Comment on lines -366 to +360
keyboard = InlineKeyboardMarkup([[
InlineKeyboardButton(
"Demote", callback_data="demote_({})".format(user_member.user.id))
]])
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Demote", callback_data=f"demote_({user_member.user.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 fullpromote refactored with the following changes:

Comment on lines -414 to +398
if not user_member.status == "administrator":
if user_member.status != "administrator":
Copy link
Author

Choose a reason for hiding this comment

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

Function demote refactored with the following changes:

Comment on lines 553 to 561
is_group = chat.type != "private" and chat.type != "channel"
is_group = chat.type not in ["private", "channel"]
prev_message = update.effective_message.reply_to_message

if prev_message is None:
msg.reply_text("Reply a message to pin it!")
return

is_silent = True
if len(args) >= 1:
if prev_message and is_group:
is_silent = (
args[0].lower() != "notify"
or args[0].lower() == "loud"
or args[0].lower() == "violent"
(
args[0].lower() != "notify"
or args[0].lower() == "loud"
or args[0].lower() == "violent"
)
if len(args) >= 1
else True
)

if prev_message and is_group:
try:
bot.pinChatMessage(
chat.id, prev_message.message_id, disable_notification=is_silent
)
msg.reply_text(
f"I have pinned a message.",
"I have pinned a message.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"👀 Go to message", url=f"{message_link}")
"👀 Go to message", url=f"{message_link}"
)
]
]
),
),
Copy link
Author

Choose a reason for hiding this comment

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

Function pin refactored with the following changes:

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

Successfully merging this pull request may close these issues.

None yet

0 participants