Skip to content

Commit

Permalink
add fban support to gban (UsergeTeam#439)
Browse files Browse the repository at this point in the history
* add fban support

* add FBAN_CHAT_ID in config

* suggested commit

* add FBAN_CHAT_ID
  • Loading branch information
Krishna-Singhal authored Jan 14, 2022
1 parent aa0cb4b commit 451ae0f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ WORKERS=""
# Telegram Chat id For Updates of Rss Feed
RSS_CHAT_ID=""

# Telegram Chat id to Fban User
# add your federation bots to chat and copy chat_id of that chat
FBAN_CHAT_ID=""

# Googel Drive API Keys from https://console.developers.google.com/
G_DRIVE_CLIENT_ID=""
G_DRIVE_CLIENT_SECRET=""
Expand Down
1 change: 1 addition & 0 deletions userge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Config:
ALLOWED_COMMANDS: Set[str] = set()
IGNORE_VERIFIED_CHATS = True
ANTISPAM_SENTRY = False
FBAN_CHAT_ID = int(os.environ.get("FBAN_CHAT_ID", 0))
RUN_DYNO_SAVER = False
HEROKU_APP = heroku3.from_key(HEROKU_API_KEY).apps()[HEROKU_APP_NAME] \
if HEROKU_ENV and HEROKU_API_KEY and HEROKU_APP_NAME else None
Expand Down
30 changes: 30 additions & 0 deletions userge/plugins/admin/gban.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ async def gban_user(message: Message):
'user_id': user_id,
'reason': reason,
'chat_ids': gbanned_chats})
if Config.FBAN_CHAT_ID and not message.client.is_bot:
mention = None # to avoid peer id invalid
if message.reply_to_message and message.reply_to_message.from_user:
mention = message.reply_to_message.from_user.mention
elif message.entities:
for i in message.entities:
if i.type == "text_mention":
mention = i.user.mention
break
if mention:
await message.client.send_message(
Config.FBAN_CHAT_ID,
f"/fban {mention} {reason}"
)
await CHANNEL.log(f'$FBAN #prid{user_id} ⬆️')
replied = message.reply_to_message
if replied:
if replied.text:
Expand Down Expand Up @@ -152,6 +167,21 @@ async def ungban_user(message: Message):
f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`")
await GBAN_USER_BASE.delete_one({'firstname': firstname, 'user_id': user_id})
if Config.FBAN_CHAT_ID and not message.client.is_bot:
mention = None # to avoid peer id invalid
if message.reply_to_message and message.reply_to_message.from_user:
mention = message.reply_to_message.from_user.mention
elif message.entities:
for i in message.entities:
if i.type == "text_mention":
mention = i.user.mention
break
if mention:
await message.client.send_message(
Config.FBAN_CHAT_ID,
f"/unfban {mention}"
)
await CHANNEL.log(f'$UNFBAN #prid{user_id} ⬆️')
LOG.info("UnGbanned %s", str(user_id))


Expand Down

0 comments on commit 451ae0f

Please sign in to comment.