Merge pull request #80 from Xtao-Labs/revert-79-master

Revert "portball v1.40 - ignore msg if sender is not admin"
This commit is contained in:
Pentacene 2020-11-28 18:09:10 +08:00 committed by GitHub
commit f7f6e76292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 41 deletions

View File

@ -152,7 +152,7 @@
}, },
{ {
"name": "portball", "name": "portball",
"version": "1.40", "version": "1.31",
"section": "chat", "section": "chat",
"maintainer": "Pentacene", "maintainer": "Pentacene",
"size": "3.6 kb", "size": "3.6 kb",

View File

@ -6,50 +6,44 @@ from datetime import timedelta
from telethon.tl.types import ChannelParticipantsAdmins from telethon.tl.types import ChannelParticipantsAdmins
@listener(is_plugin=True, outgoing=True, incoming=True, command="portball", @listener(is_plugin=True, outgoing=True, command="portball",
description="回复你要临时禁言的人的消息来实现XX秒的禁言", description="回复你要临时禁言的人的消息来实现XX秒的禁言",
parameters="<理由>(空格)<时间/秒>") parameters="<理由>(空格)<时间/秒>")
async def portball(context): async def portball(context):
reply = await context.get_reply_message() reply = await context.get_reply_message()
if context.is_group: if context.is_group:
admins = await context.client.get_participants(context.chat, filter=ChannelParticipantsAdmins) if reply:
# if message sender is one of admins or group anonymous bot action = context.arguments.split()
if (context.sender in admins) or (context.sender_id == 1087968824): if reply.sender.last_name == None:
# if this msg reply to a message last_name = ''
if reply: else:
action = context.arguments.split() last_name = reply.sender.last_name
# get sender's last_name if len(action) < 2:
if reply.sender.last_name == None: notification = await bot.send_message(context.chat_id, '格式是\n-portball 理由 秒数\n真蠢', reply_to = context.id)
last_name = '' await sleep(10)
else: await notification.delete()
last_name = reply.sender.last_name try:
# if something wrong with the command await context.delete()
if len(action) < 2: except:
notification = await bot.send_message(context.chat_id, '格式是\n-portball 理由 秒数\n真蠢', reply_to = context.id) pass
await sleep(10) return False
await notification.delete() if int(action[1])<60:
try: notification = await bot.send_message(context.chat_id, '诶呀不要小于60秒啦', reply_to = context.id)
await context.delete() await sleep(10)
except: await notification.delete()
pass try:
return False await context.delete()
# if time of portball less than 60 seconds except:
if int(action[1])<60: pass
notification = await bot.send_message(context.chat_id, '诶呀不要小于60秒啦', reply_to = context.id) return False
await sleep(10) admins = await context.client.get_participants(context.chat, filter=ChannelParticipantsAdmins)
await notification.delete() if (context.sender in admins) or (context.sender_id == 1087968824):
try:
await context.delete()
except:
pass
return False
# portball
try: try:
await bot.edit_permissions(context.chat_id, reply.sender.id, timedelta(seconds=int(action[1].replace(' ',''))), send_messages=False, send_media=False, send_stickers=False, send_gifs=False, send_games=False, send_inline=False, send_polls=False, invite_users=False, change_info=False, pin_messages=False) await bot.edit_permissions(context.chat_id, reply.sender.id, timedelta(seconds=int(action[1].replace(' ',''))), send_messages=False, send_media=False, send_stickers=False, send_gifs=False, send_games=False, send_inline=False, send_polls=False, invite_users=False, change_info=False, pin_messages=False)
portball_message = await bot.send_message( portball_message = await bot.send_message(
context.chat_id, context.chat_id,
f'[{reply.sender.first_name}{last_name}](tg://user?id={reply.sender.id}) 由于 {action[0]} 被塞了{action[1]}秒口球.\n f'[{reply.sender.first_name}{last_name}](tg://user?id={reply.sender.id}) 由于 {action[0]} \n'
f'到期自动拔出,无后遗症.', f'被暂时禁言{action[1]}',
reply_to = reply.id reply_to = reply.id
) )
await context.delete() await context.delete()
@ -63,15 +57,14 @@ async def portball(context):
notification = await bot.send_message(context.chat_id, '错误:我没有管理员权限或我的权限比被封禁的人要小', reply_to = context.id) notification = await bot.send_message(context.chat_id, '错误:我没有管理员权限或我的权限比被封禁的人要小', reply_to = context.id)
await sleep(10) await sleep(10)
await notification.delete() await notification.delete()
# if not reply to any message
else: else:
notification = await bot.send_message(context.chat_id, '你好蠢诶,都没有回复人,我哪知道你要搞谁的事情……', reply_to = context.id) notification = await bot.send_message(context.chat_id, '诶呀你不是管理员,不要给人家塞口球啊', reply_to = context.id)
await sleep(10) await sleep(10)
await notification.delete() await notification.delete()
# if sender is not admin
else: else:
return notification = await bot.send_message(context.chat_id, '你好蠢诶,都没有回复人,我哪知道你要搞谁的事情……', reply_to = context.id)
await sleep(10)
await notification.delete()
else: else:
notification = await bot.send_message(context.chat_id, '你好蠢诶,又不是群组,怎么禁言啦!', reply_to = context.id) notification = await bot.send_message(context.chat_id, '你好蠢诶,又不是群组,怎么禁言啦!', reply_to = context.id)
await sleep(10) await sleep(10)