Skip to content

Commit

Permalink
sudo enable/disable + antispam enable/disable + kang fix for username…
Browse files Browse the repository at this point in the history
… + custom sticker pack name + shutdown cmd + heroku logs support + some env cleanups
  • Loading branch information
rking32 committed Aug 15, 2020
1 parent fd2c07d commit 5b06ac3
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 191 deletions.
119 changes: 5 additions & 114 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,122 +12,13 @@
"website": "https://github.com/Userge",
"success_url": "https://t.me/theUserge",
"env": {
"API_ID": {
"description": "Get this value from https://my.telegram.org"
},
"API_HASH": {
"description": "Get this value from https://my.telegram.org"
},
"API_ID": {"description": "Get this value from https://my.telegram.org"},
"API_HASH": {"description": "Get this value from https://my.telegram.org"},
"DATABASE_URL": {"description": "Mongodb url from https://cloud.mongodb.com/"},
"LOG_CHANNEL_ID": {"description": "Telegram Log Channel ID"},
"HU_STRING_SESSION": {
"description": "Get it by 'https://GenUserGeString.usergeuserbot.repl.run' or use `bash genStr`",
"required": false
},
"BOT_TOKEN": {
"description": "Get this from https://t.me/botfather if you like to use userge as a bot",
"required": false
},
"OWNER_ID": {
"description": "Your user_id if you are gonna use userge as a bot",
"required": false
},
"WORKERS": {
"description": "Userbot Workers Count : Default = 4",
"required": false
},
"DATABASE_URL": {
"description": "Mongodb url from https://cloud.mongodb.com/"
},
"G_DRIVE_CLIENT_ID": {
"description": "Googel Drive API Keys from https://console.developers.google.com/",
"required": false
},
"G_DRIVE_CLIENT_SECRET": {
"description": "Googel Drive API Keys from https://console.developers.google.com/",
"required": false
},
"G_DRIVE_IS_TD": {
"description": "Set true if it is TeamDrive",
"required": false
},
"LOG_CHANNEL_ID": {
"description": "Telegram Log Channel ID"
},
"G_DRIVE_INDEX_LINK": {
"description": "Index link for gdrive",
"required": false
},
"LOAD_UNOFFICIAL_PLUGINS": {
"description": "Set True if your like to use unofficial plugins",
"required": false
},
"DOWN_PATH": {
"description": "Set name to your working directory",
"required": false
},
"PREFERRED_LANGUAGE": {
"description": "Your Languge ( ex: if english => 'en' )",
"required": false
},
"CURRENCY_API": {
"description": "get API key from 'https://free.currencyconverterapi.com'",
"required": false
},
"OCR_SPACE_API_KEY": {
"description": "get OCR API key from 'http://eepurl.com/bOLOcf'",
"required": false
},
"WEATHER_DEFCITY": {
"description": "add default city for weather",
"required": false
},
"OPEN_WEATHER_MAP": {
"description": "Weather API get it from 'https://openweathermap.org/",
"required": false
},
"ANTISPAM_SENTRY": {
"description": "Toggle API Auto Bans, Active if set to True",
"required": false
},
"SPAM_WATCH_API": {
"description": "SpamWatch API get it from @SpamWatch in Telegram",
"required": false
},
"REMOVE_BG_API_KEY": {
"description": "RemoveBg API Key get it from https://www.remove.bg/api",
"required": false
},
"G_DRIVE_PARENT_ID": {
"description": "GDrive Folder ID",
"required": false
},
"HEROKU_APP_NAME": {
"description": "given app name to the heroku app",
"required": false
},
"HEROKU_API_KEY": {
"description": "get a Heroku API key from http://dashboard.heroku.com/account",
"required": false
},
"UPSTREAM_REPO": {
"description": "set this to your USERGE fork on GitHub",
"required": false
},
"CMD_TRIGGER": {
"description": "set command prefix",
"required": false
},
"SUDO_TRIGGER": {
"description": "set command prefix for SUDO users",
"required": false
},
"FINISHED_PROGRESS_STR": {
"description": "single character for finished progress",
"required": false
},
"UNFINISHED_PROGRESS_STR": {
"description": "single character for unfinished progress",
"required": false
}
"required": false}
},
"addons": [],
"buildpacks": [
Expand Down
8 changes: 4 additions & 4 deletions config.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ WEATHER_DEFCITY=""
SPAM_WATCH_API=""


# Toggle API Auto Bans, Active if set to true
ANTISPAM_SENTRY=false


# Weather API get it from 'https://openweathermap.org/'
OPEN_WEATHER_MAP=""

Expand Down Expand Up @@ -125,6 +121,10 @@ FINISHED_PROGRESS_STR='█'
UNFINISHED_PROGRESS_STR=''


# custom name for your sticker pack
CUSTOM_PACK_NAME=""


# ----------- Only If Using Heroku ----------- #


Expand Down
3 changes: 1 addition & 2 deletions init/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ _checkDefaultVars() {
replyLastMessage "Checking Default ENV Vars ..."
declare -rA def_vals=(
[WORKERS]=4
[ANTISPAM_SENTRY]=false
[PREFERRED_LANGUAGE]="en"
[DOWN_PATH]="downloads"
[UPSTREAM_REMOTE]="upstream"
Expand All @@ -67,7 +66,7 @@ _checkDefaultVars() {
DOWN_PATH=${DOWN_PATH%/}/
[[ -n $HEROKU_API_KEY && -n $HEROKU_APP_NAME ]] \
&& declare -gx HEROKU_GIT_URL="https://api:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git"
for var in ANTISPAM_SENTRY G_DRIVE_IS_TD LOAD_UNOFFICIAL_PLUGINS; do
for var in G_DRIVE_IS_TD LOAD_UNOFFICIAL_PLUGINS; do
eval $var=$(tr "[:upper:]" "[:lower:]" <<< ${!var})
done
local nameAndUName=$(grep -oP "(?<=\/\/)(.+)(?=\@)" <<< $DATABASE_URL)
Expand Down
4 changes: 3 additions & 1 deletion userge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Config:
SUDO_TRIGGER = os.environ.get("SUDO_TRIGGER")
FINISHED_PROGRESS_STR = os.environ.get("FINISHED_PROGRESS_STR")
UNFINISHED_PROGRESS_STR = os.environ.get("UNFINISHED_PROGRESS_STR")
CUSTOM_PACK_NAME = os.environ.get("CUSTOM_PACK_NAME")
UPSTREAM_REPO = os.environ.get("UPSTREAM_REPO")
UPSTREAM_REMOTE = os.environ.get("UPSTREAM_REMOTE")
SCREENSHOT_API = os.environ.get("SCREENSHOT_API", None)
Expand All @@ -62,7 +63,6 @@ class Config:
HEROKU_APP_NAME = os.environ.get("HEROKU_APP_NAME", None)
HEROKU_GIT_URL = os.environ.get("HEROKU_GIT_URL", None)
G_DRIVE_IS_TD = os.environ.get("G_DRIVE_IS_TD") == "true"
ANTISPAM_SENTRY = os.environ.get("ANTISPAM_SENTRY") == "true"
LOAD_UNOFFICIAL_PLUGINS = os.environ.get("LOAD_UNOFFICIAL_PLUGINS") == "true"
TMP_PATH = "userge/plugins/temp/"
MAX_MESSAGE_LENGTH = 4096
Expand All @@ -72,8 +72,10 @@ class Config:
ALLOWED_CHATS = Filters.chat([])
ALLOW_ALL_PMS = True
USE_USER_FOR_CLIENT_CHECKS = False
SUDO_ENABLED = False
SUDO_USERS: Set[int] = set()
ALLOWED_COMMANDS: Set[str] = set()
ANTISPAM_SENTRY = False
HEROKU_APP = None


Expand Down
5 changes: 2 additions & 3 deletions userge/core/types/raw/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ def parse(cls, command: str, # pylint: disable=arguments-differ
lambda _, m:
not m.outgoing
and (
(Config.OWNER_ID
and (m.from_user and m.from_user.id == Config.OWNER_ID))
or ((cname.lstrip(trigger) in Config.ALLOWED_COMMANDS)
(Config.OWNER_ID and (m.from_user and m.from_user.id == Config.OWNER_ID))
or (Config.SUDO_ENABLED and (cname.lstrip(trigger) in Config.ALLOWED_COMMANDS)
and (m.from_user and m.from_user.id in Config.SUDO_USERS)))
and (m.text.startswith(Config.SUDO_TRIGGER) if trigger else True))
filters_ = filters_ & (outgoing_flt | incoming_flt)
Expand Down
22 changes: 22 additions & 0 deletions userge/plugins/admin/gban.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,34 @@

from userge import userge, Message, Config, get_collection, Filters

SAVED_SETTINGS = get_collection("CONFIGS")
GBAN_USER_BASE = get_collection("GBAN_USER")
WHITELIST = get_collection("WHITELIST_USER")
CHANNEL = userge.getCLogger(__name__)
LOG = userge.getLogger(__name__)


async def _init() -> None:
s_o = await SAVED_SETTINGS.find_one({'_id': 'ANTISPAM_ENABLED'})
if s_o:
Config.ANTISPAM_SENTRY = s_o['data']


@userge.on_cmd("antispam", about={
'header': "enable / disable antispam",
'description': "Toggle API Auto Bans"}, allow_channels=False)
async def antispam_(message: Message):
""" enable / disable antispam """
if Config.ANTISPAM_SENTRY:
Config.ANTISPAM_SENTRY = False
await message.edit("`antispam disabled !`", del_in=3)
else:
Config.ANTISPAM_SENTRY = True
await message.edit("`antispam enabled !`", del_in=3)
await SAVED_SETTINGS.update_one(
{'_id': 'ANTISPAM_ENABLED'}, {"$set": {'data': Config.ANTISPAM_SENTRY}}, upsert=True)


@userge.on_cmd("gban", about={
'header': "Globally Ban A User",
'description': "Adds User to your GBan List. "
Expand Down
18 changes: 8 additions & 10 deletions userge/plugins/fun/kang.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
async def kang_(message: Message):
""" kang a sticker """
user = await userge.get_me()
if not user.username:
user.username = user.first_name or user.id
replied = message.reply_to_message
photo = None
emoji = None
Expand Down Expand Up @@ -71,8 +69,9 @@ async def kang_(message: Message):
pack = int(args[0])
else:
emoji = args[0]
packname = f"a{user.id}_by_{user.username}_{pack}"
packnick = f"@{user.username}'s kang pack Vol.{pack}"
packname = f"a{user.id}_by_userge_{pack}"
custom_packnick = Config.CUSTOM_PACK_NAME or f"@{user.id}'s kang pack"
packnick = f"{custom_packnick} Vol.{pack}"
cmd = '/newpack'
if resize:
photo = resize_photo(photo)
Expand Down Expand Up @@ -101,8 +100,8 @@ def get_response():
limit = "50" if is_anim else "120"
while limit in msg.text:
pack += 1
packname = f"a{user.id}_by_{user.username}_{pack}"
packnick = f"@{user.username}'s kang pack Vol.{pack}"
packname = f"a{user.id}_by_userge_{pack}"
packnick = f"{custom_packnick} Vol.{pack}"
await message.edit("`Switching to Pack " + str(pack) +
" due to insufficient space`")
await conv.send_message(packname)
Expand Down Expand Up @@ -154,8 +153,8 @@ def get_response():
await conv.send_document(photo)
rsp = await conv.get_response(mark_read=True)
if "Sorry, the file type is invalid." in rsp.text:
await args.edit("`Failed to add sticker, use` @Stickers "
"`bot to add the sticker manually.`")
await message.edit("`Failed to add sticker, use` @Stickers "
"`bot to add the sticker manually.`")
return
await conv.send_message(emoji)
await conv.get_response(mark_read=True)
Expand All @@ -168,8 +167,7 @@ def get_response():
await conv.get_response(mark_read=True)
await conv.send_message(packname)
await conv.get_response(mark_read=True)
await message.edit(f"`Sticker kanged successfully!`\n"
f"Pack can be found [here](t.me/addstickers/{packname})")
await message.edit(f"**Sticker** [kanged](t.me/addstickers/{packname})!")
if os.path.exists(str(photo)):
os.remove(photo)

Expand Down
29 changes: 17 additions & 12 deletions userge/plugins/tools/alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyrogram.errors.exceptions import FileIdInvalid, FileReferenceEmpty
from pyrogram.errors.exceptions.bad_request_400 import BadRequest, ChannelInvalid, MediaEmpty

from userge.core.ext import RawClient
from userge import userge, Message, Config, versions, get_version

LOGO_STICKER_ID, LOGO_STICKER_REF = None, None
Expand All @@ -20,22 +21,26 @@ async def alive(message: Message):
await message.delete()
await sendit(message)
output = f"""
**USERGE is Up and Running**
__Durable as a Serge__
• **uptime** : `{userge.uptime}`
• **python version** : `{versions.__python_version__}`
• **pyrogram version** : `{versions.__pyro_version__}`
• **userge version** : `{get_version()}`
• **unofficial enabled** : `{Config.LOAD_UNOFFICIAL_PLUGINS}`
• **license** : {versions.__license__}
• **copyright** : {versions.__copyright__}
• **repo** : [Userge]({Config.UPSTREAM_REPO})
**uptime** : `{userge.uptime}`
**version** : `{get_version()}`
• **sudo** : `{_parse_arg(Config.SUDO_ENABLED)}`
• **antispam** : `{_parse_arg(Config.ANTISPAM_SENTRY)}`
• **dualmode** : `{_parse_arg(RawClient.DUAL_MODE)}`
• **unofficial** : `{_parse_arg(Config.LOAD_UNOFFICIAL_PLUGINS)}`
**__python__** : `{versions.__python_version__}`
**__pyrogram__** : `{versions.__pyro_version__}`
**{versions.__license__}** | **{versions.__copyright__}** | **[Repo]({Config.UPSTREAM_REPO})**
"""
await message.client.send_message(message.chat.id, output, disable_web_page_preview=True)


def _parse_arg(arg: bool) -> str:
return "enabled" if arg else "disabled"


async def refresh_id():
global LOGO_STICKER_ID, LOGO_STICKER_REF # pylint: disable=global-statement
sticker = (await userge.get_messages('theUserge', 8)).sticker
Expand Down
7 changes: 2 additions & 5 deletions userge/plugins/tools/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@
'header': "message object to json",
'usage': "reply {tr}json to any message"})
async def jsonify(message: Message):
the_real_message = str(message.reply_to_message) if message.reply_to_message \
else str(message)
await message.edit_or_send_as_file(text=the_real_message,
filename="json.txt",
caption="Too Large")
msg = str(message.reply_to_message) if message.reply_to_message else str(message)
await message.edit_or_send_as_file(text=msg, filename="json.txt", caption="Too Large")
22 changes: 17 additions & 5 deletions userge/plugins/tools/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# All rights reserved.

from userge import userge, Message, logging
from userge import userge, Message, logging, Config, pool

_LEVELS = {
'debug': logging.DEBUG,
Expand All @@ -17,13 +17,25 @@
}


@userge.on_cmd("logs", about={'header': "check userge logs"}, allow_channels=False)
@userge.on_cmd("logs", about={
'header': "check userge logs",
'flags': {
'-h': "get heroku logs",
'-l': "heroku logs lines limit : default 100"}}, allow_channels=False)
async def check_logs(message: Message):
""" check logs """
await message.edit("`checking logs ...`")
await message.client.send_document(chat_id=message.chat.id,
document="logs/userge.log",
caption='userge.log')
if '-h' in message.flags and Config.HEROKU_APP:
limit = int(message.flags.get('-l', 100))
logs = await pool.run_in_thread(Config.HEROKU_APP.get_log)(lines=limit)
await message.client.send_as_file(chat_id=message.chat.id,
text=logs,
filename='userge-heroku.log',
caption=f'userge-heroku.log [ {limit} lines ]')
else:
await message.client.send_document(chat_id=message.chat.id,
document="logs/userge.log",
caption='userge.log')
await message.delete()


Expand Down
Loading

0 comments on commit 5b06ac3

Please sign in to comment.