Skip to content

Commit

Permalink
[SpamWatch] Implement Spamwatch API
Browse files Browse the repository at this point in the history
  • Loading branch information
TsunayoshiSawada committed Jul 27, 2020
1 parent 39b7813 commit b5bbc8f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
12 changes: 12 additions & 0 deletions SaitamaRobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
import time
import spamwatch

import telegram.ext as tg
from telethon import TelegramClient
Expand Down Expand Up @@ -154,6 +155,7 @@
AI_API_KEY = Config.AI_API_KEY
WALL_API = Config.WALL_API
SUPPORT_CHAT = Config.SUPPORT_CHAT


try:
BL_CHATS = set(int(x) for x in Config.BL_CHATS or [])
Expand All @@ -164,6 +166,16 @@
SUDO_USERS.add(OWNER_ID)
DEV_USERS.add(OWNER_ID)

#SpamWatch Thingies
spamwatch_api = os.environ.get('sw_api', None)

if spamwatch_api == "None":
sw = None
LOGGER.warning("SpamWatch API key missing! recheck your config.")
else:
sw = spamwatch.Client(spamwatch_api)


updater = tg.Updater(TOKEN, workers=WORKERS, use_context=True)
telethn = TelegramClient("saitama", API_ID, API_HASH)
dispatcher = updater.dispatcher
Expand Down
21 changes: 20 additions & 1 deletion SaitamaRobot/modules/global_bans.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,27 @@ def gbanlist(update: Update, context: CallbackContext):

def check_and_ban(update, user_id, should_message=True):

chat = update.effective_chat # type: Optional[Chat]
sw_ban = sw.get_ban(int(user_id))
if sw_ban:
update.effective_chat.kick_member(user_id)
if should_message:
update.effective_message.reply_text(
"<b>Spamwatch Alert:</b> This user is not safe!\n"
"<code>*rekts them from here*.</code>\n"
"<b>Appeal chat:</b> @SpamWatchSupport",
parse_mode=ParseMode.HTML)
return
else:
return

if sql.is_user_gbanned(user_id):
update.effective_chat.kick_member(user_id)
if should_message:
update.effective_message.reply_text(
"<b>Alert:</b> This user is globally banned.\n"
"<code>*bans them from here*.</code>\n"
f"Appeal chat: {SUPPORT_CHAT}",
f"<b>Appeal chat:</b> {SUPPORT_CHAT}",
parse_mode=ParseMode.HTML)


Expand Down Expand Up @@ -472,6 +486,11 @@ def __chat_settings__(chat_id, user_id):
you and your groups by removing spam flooders as quickly as possible. They can be disabled for your group by calling \
`/gbanstat`
*Note:* Users can appeal gbans or report spammers at {SUPPORT_CHAT}
Saitama also integrates @Spamwatch API into gbans to remove Spammers as much as possible from your chatroom!
*What is SpamWatch?*
SpamWatch maintains a large constantly updated ban-list of spambots, trolls, bitcoin spammers and unsavoury characters[.](https://telegra.ph/file/f584b643c6f4be0b1de53.jpg)
Constantly help banning spammers off from your group automatically So, you wont have to worry about spammers storming your group.
"""

GBAN_HANDLER = CommandHandler("gban", gban)
Expand Down
12 changes: 12 additions & 0 deletions SaitamaRobot/modules/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def new_member(update: Update, context: CallbackContext):
should_mute = True
welcome_bool = True

if sw != None:
sw_ban = sw.get_ban(new_mem.id)
if sw_ban:
return

if should_welc:

reply = update.message.message_id
Expand Down Expand Up @@ -365,6 +370,13 @@ def left_member(update: Update, context: CallbackContext):

left_mem = update.effective_message.left_chat_member
if left_mem:

# Thingy for spamwatched users
if sw != None:
sw_ban = sw.get_ban(left_mem.id)
if sw_ban:
return

# Dont say goodbyes to gbanned users
if is_user_gbanned(left_mem.id):
return
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ speedtest-cli
coffeehouse
regex
wikipedia
telethon
telethon
spamwatch

0 comments on commit b5bbc8f

Please sign in to comment.