Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #191 from AnimeKaizoku/shiken
Browse files Browse the repository at this point in the history
More upgrades to master version
  • Loading branch information
TsunayoshiSawada authored Aug 27, 2020
2 parents 4930cab + b8670ce commit 7ff0d8b
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 138 deletions.
4 changes: 2 additions & 2 deletions SaitamaRobot/modules/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ def get_chat(chat_id, chat_data):
__help__ = """
*Only for group owner:*
× /import: Reply to the backup file for the butler / emilia group to import as much as possible, making transfers very easy! \
/import: Reply to the backup file for the butler / emilia group to import as much as possible, making transfers very easy! \
Note that files / photos cannot be imported due to telegram restrictions.
× /export: Export group data, which will be exported are: rules, notes (documents, images, music, video, audio, voice, text, text buttons) \
/export: Export group data, which will be exported are: rules, notes (documents, images, music, video, audio, voice, text, text buttons) \
"""

Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def __chat_settings__(chat_id, user_id):


def __stats__():
return "× {} blacklist triggers, across {} chats.".format(
return " {} blacklist triggers, across {} chats.".format(
sql.num_blacklist_filters(), sql.num_blacklist_filter_chats())


Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/blacklist_stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def __chat_settings__(chat_id, user_id):


def __stats__():
return "{} blacklist stickers, across {} chats.".format(
return "{} blacklist stickers, across {} chats.".format(
sql.num_stickers_filters(), sql.num_stickers_filter_chats())


Expand Down
10 changes: 5 additions & 5 deletions SaitamaRobot/modules/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ def connect_button(update, context):
Sometimes, you just want to add some notes and filters to a group chat, but you don't want everyone to see; This is where connections come in...
This allows you to connect to a chat's database, and add things to it without the commands appearing in chat! For obvious reasons, you need to be an admin to add things; but any member in the group can view your data.
× /connect: Connects to chat (Can be done in a group by /connect or /connect <chat id> in PM)
× /connection: List connected chats
× /disconnect: Disconnect from a chat
× /helpconnect: List available commands that can be used remotely
/connect: Connects to chat (Can be done in a group by /connect or /connect <chat id> in PM)
/connection: List connected chats
/disconnect: Disconnect from a chat
/helpconnect: List available commands that can be used remotely
*Admin only:*
× /allowconnect <yes/no>: allow a user to connect to a chat
/allowconnect <yes/no>: allow a user to connect to a chat
"""

CONNECT_CHAT_HANDLER = CommandHandler("connect", connect_chat, pass_args=True)
Expand Down
4 changes: 2 additions & 2 deletions SaitamaRobot/modules/cust_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def list_handlers(update, context):
return

for keyword in all_handlers:
entry = " × `{}`\n".format(escape_markdown(keyword))
entry = " `{}`\n".format(escape_markdown(keyword))
if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH:
send_message(
update.effective_message,
Expand Down Expand Up @@ -492,7 +492,7 @@ def get_exception(excp, filt, chat):


def __stats__():
return "× {} filters, across {} chats.".format(sql.num_filters(),
return " {} filters, across {} chats.".format(sql.num_filters(),
sql.num_chats())


Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def commands(update: Update, context: CallbackContext):
build_curr_disabled(chat.id), parse_mode=ParseMode.MARKDOWN)

def __stats__():
return f"{sql.num_disabled()} disabled items, across {sql.num_chats()} chats."
return f"{sql.num_disabled()} disabled items, across {sql.num_chats()} chats."

def __migrate__(old_chat_id, new_chat_id):
sql.migrate_chat(old_chat_id, new_chat_id)
Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/feds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ def welcome_fed(update: Update, context: CallbackContext):
def __stats__():
all_fbanned = sql.get_all_fban_users_global()
all_feds = sql.get_all_feds_users_global()
return "{} banned users across {} Federations".format(
return "{} banned users across {} Federations".format(
len(all_fbanned), len(all_feds))


Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/global_bans.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def gbanstat(update: Update, context: CallbackContext):


def __stats__():
return f"{sql.num_gbanned_users()} gbanned users."
return f"{sql.num_gbanned_users()} gbanned users."


def __user_info__(user_id):
Expand Down
53 changes: 38 additions & 15 deletions SaitamaRobot/modules/helper_funcs/msg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,21 @@ def get_welcome_type(msg: Message):
content = None
text = ""

args = msg.text.split(None,
1) # use python's maxsplit to separate cmd and args

buttons = []
# determine what the contents of the filter are - text, image, sticker, etc
if len(args) >= 2:
offset = len(args[1]) - len(
msg.text) # set correct offset relative to command + notename
text, buttons = button_markdown_parser(
args[1], entities=msg.parse_entities(), offset=offset)
if buttons:
data_type = Types.BUTTON_TEXT
try:
if msg.reply_to_message:
if msg.reply_to_message.text:
args = msg.reply_to_message.text
else:
args = msg.reply_to_message.caption
else:
data_type = Types.TEXT
args = msg.text.split(
None, 1) # use python's maxsplit to separate cmd and args
except AttributeError:
args = False

elif msg.reply_to_message and msg.reply_to_message.sticker:
if msg.reply_to_message and msg.reply_to_message.sticker:
content = msg.reply_to_message.sticker.file_id
text = msg.reply_to_message.caption
text = None
data_type = Types.STICKER

elif msg.reply_to_message and msg.reply_to_message.document:
Expand Down Expand Up @@ -135,6 +132,32 @@ def get_welcome_type(msg: Message):
text = msg.reply_to_message.caption
data_type = Types.VIDEO

elif msg.reply_to_message and msg.reply_to_message.video_note:
content = msg.reply_to_message.video_note.file_id
text = None
data_type = Types.VIDEO_NOTE

buttons = []
# determine what the contents of the filter are - text, image, sticker, etc
if args:
if msg.reply_to_message:
argumen = msg.reply_to_message.caption if msg.reply_to_message.caption else ""
offset = 0 # offset is no need since target was in reply
entities = msg.reply_to_message.parse_entities()
else:
argumen = args[1]
offset = len(argumen) - len(
msg.text) # set correct offset relative to command + notename
entities = msg.parse_entities()
text, buttons = button_markdown_parser(
argumen, entities=entities, offset=offset)

if not data_type:
if text and buttons:
data_type = Types.BUTTON_TEXT
elif text:
data_type = Types.TEXT

return text, data_type, content, buttons


Expand Down
4 changes: 2 additions & 2 deletions SaitamaRobot/modules/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,10 @@ def build_lock_message(chat_id):
locklist.sort()
# Building lock list string
for x in locklist:
res += "\n × {}".format(x)
res += "\n {}".format(x)
res += "\n\n*" + "These are the current chat permissions:" + "*"
for x in permslist:
res += "\n × {}".format(x)
res += "\n {}".format(x)
return res


Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/log_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def unsetlog(update: Update, context: CallbackContext):
message.reply_text("No log channel has been set yet!")

def __stats__():
return f"{sql.num_logchannels()} log channels set."
return f"{sql.num_logchannels()} log channels set."

def __migrate__(old_chat_id, new_chat_id):
sql.migrate_chat(old_chat_id, new_chat_id)
Expand Down
10 changes: 7 additions & 3 deletions SaitamaRobot/modules/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,14 @@ def echo(update: Update, context: CallbackContext):
message = update.effective_message

if message.reply_to_message:
message.reply_to_message.reply_text(args[1])
message.reply_to_message.reply_text(
args[1], parse_mode="MARKDOWN", disable_web_page_preview=True)
else:
message.reply_text(args[1], quote=False)

message.reply_text(
args[1],
quote=False,
parse_mode="MARKDOWN",
disable_web_page_preview=True)
message.delete()


Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def __import_data__(chat_id, data):


def __stats__():
return f"{sql.num_notes()} notes, across {sql.num_chats()} chats."
return f"{sql.num_notes()} notes, across {sql.num_chats()} chats."


def __migrate__(old_chat_id, new_chat_id):
Expand Down
2 changes: 1 addition & 1 deletion SaitamaRobot/modules/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def clear_rules(update: Update, context: CallbackContext):


def __stats__():
return f"{sql.num_chats()} chats have rules set."
return f"{sql.num_chats()} chats have rules set."


def __import_data__(chat_id, data):
Expand Down
17 changes: 12 additions & 5 deletions SaitamaRobot/modules/sql/welcome_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class Welcome(BASE):
chat_id = Column(String(14), primary_key=True)
should_welcome = Column(Boolean, default=True)
should_goodbye = Column(Boolean, default=True)
custom_content = Column(UnicodeText, default=None)

custom_welcome = Column(
UnicodeText, default=random.choice(DEFAULT_WELCOME_MESSAGES))
Expand Down Expand Up @@ -361,10 +362,11 @@ def get_welc_pref(chat_id):
welc = SESSION.query(Welcome).get(str(chat_id))
SESSION.close()
if welc:
return welc.should_welcome, welc.custom_welcome, welc.welcome_type
return welc.should_welcome, welc.custom_welcome, welc.custom_content, welc.welcome_type

else:
# Welcome by default.
return True, DEFAULT_WELCOME, Types.TEXT
return True, DEFAULT_WELCOME, None, Types.TEXT


def get_gdbye_pref(chat_id):
Expand Down Expand Up @@ -423,7 +425,11 @@ def set_gdbye_preference(chat_id, should_goodbye):
SESSION.commit()


def set_custom_welcome(chat_id, custom_welcome, welcome_type, buttons=None):
def set_custom_welcome(chat_id,
custom_content,
custom_welcome,
welcome_type,
buttons=None):
if buttons is None:
buttons = []

Expand All @@ -432,12 +438,13 @@ def set_custom_welcome(chat_id, custom_welcome, welcome_type, buttons=None):
if not welcome_settings:
welcome_settings = Welcome(str(chat_id), True)

if custom_welcome:
if custom_welcome or custom_content:
welcome_settings.custom_content = custom_content
welcome_settings.custom_welcome = custom_welcome
welcome_settings.welcome_type = welcome_type.value

else:
welcome_settings.custom_welcome = DEFAULT_GOODBYE
welcome_settings.custom_welcome = DEFAULT_WELCOME
welcome_settings.welcome_type = Types.TEXT.value

SESSION.add(welcome_settings)
Expand Down
22 changes: 12 additions & 10 deletions SaitamaRobot/modules/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,27 @@ def broadcast(update: Update, context: CallbackContext):
if to_group:
for chat in chats:
try:
context.bot.sendMessage(int(chat.chat_id), to_send[1])
context.bot.sendMessage(
int(chat.chat_id),
to_send[1],
parse_mode="MARKDOWN",
disable_web_page_preview=True)
sleep(0.1)
except TelegramError:
failed += 1
LOGGER.warning(
"Couldn't send broadcast to %s, group name %s",
str(chat.chat_id), str(chat.chat_name))
if to_user:
for user in users:
try:
context.bot.sendMessage(int(user.user_id), to_send[1])
context.bot.sendMessage(
int(user.user_id),
to_send[1],
parse_mode="MARKDOWN",
disable_web_page_preview=True)
sleep(0.1)
except TelegramError:
failed_user += 1
LOGGER.warning("Couldn't send broadcast to %s",
str(user.user_id))

update.effective_message.reply_text(
f"Broadcast complete. {failed} groups failed to receive the message, probably due to being kicked. {failed_user} failed to receive message, probably due to being blocked"
f"Broadcast complete.\nGroups failed: {failed}.\nUsers failed: {failed_user}."
)


Expand Down Expand Up @@ -147,7 +149,7 @@ def __user_info__(user_id):


def __stats__():
return f"{sql.num_users()} users, across {sql.num_chats()} chats"
return f"{sql.num_users()} users, across {sql.num_chats()} chats"


def __migrate__(old_chat_id, new_chat_id):
Expand Down
4 changes: 2 additions & 2 deletions SaitamaRobot/modules/warns.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ def set_warn_strength(update: Update, context: CallbackContext):

def __stats__():
return (
f"{sql.num_warns()} overall warns, across {sql.num_warn_chats()} chats.\n"
f"{sql.num_warn_filters()} warn filters, across {sql.num_warn_filter_chats()} chats."
f"{sql.num_warns()} overall warns, across {sql.num_warn_chats()} chats.\n"
f"{sql.num_warn_filters()} warn filters, across {sql.num_warn_filter_chats()} chats."
)


Expand Down
Loading

0 comments on commit 7ff0d8b

Please sign in to comment.