Skip to content

Commit

Permalink
Remove errors handler + some minor tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Avinash Reddy committed Aug 7, 2019
1 parent 92d16a6 commit b8cb321
Show file tree
Hide file tree
Showing 40 changed files with 75 additions and 472 deletions.
20 changes: 2 additions & 18 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,8 @@
"description": "OCR API Key for .ocr command Get from https://ocr.space/ocrapi",
"required": false
},
"DEFAULT_BIO": {
"description": "Set a default bio to be shown when you are not listening on Spotify..",
"required": false
},
"SPOTIFY_USERNAME": {
"description": "Put your Spotify Username (your Spotify username).",
"required": false
},
"SPOTIFY_PASS": {
"description": "Put your Spotify Password.",
"required": false
},
"SPOTIFY_BIO_PREFIX": {
"description": "Put the prefix that you want to show while you listen to music",
"required": false
},
"WELCOME_MUTE": {
"description": "Mute some known spammer bots after they join.",
"ANTI_SPAMBOT": {
"description": "Report or kick some known spammer bots after they join.",
"value": "False"
},
"TMP_DOWNLOAD_DIRECTORY": {
Expand Down
15 changes: 2 additions & 13 deletions sample_config.env
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ G_DRIVE_CLIENT_SECRET = ""
G_DRIVE_AUTH_TOKEN_DATA = ""
TEMP_DOWNLOAD_DIRECTORY = ""

#
# Spotify Current Listening Music to Bio
#
DEFAULT_BIO= ""
SPOTIFY_USERNAME= ""
SPOTIFY_PASS= ""

# Bot will add before song name.
# Example: GitHub: MacTavishAO : Skillet - Feel Invincible
SPOTIFY_BIO_PREFIX= ""

# Mute some known spammer bots after
# Report or kick some known spammer bots after
# they joins
WELCOME_MUTE = False
ANTI_SPAMBOT = False
4 changes: 2 additions & 2 deletions userbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@

OPEN_WEATHER_MAP_APPID = os.environ.get("OPEN_WEATHER_MAP_APPID", None)

WELCOME_MUTE = sb(os.environ.get(
"WELCOME_MUTE", "False"
ANTI_SPAMBOT = sb(os.environ.get(
"ANTI_SPAMBOT", "False"
))

YOUTUBE_API_KEY = os.environ.get(
Expand Down
70 changes: 1 addition & 69 deletions userbot/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,72 +36,4 @@ def decorator(func):

return func

return decorator


def errors_handler(func):
async def wrapper(errors):
try:
await func(errors)

except StopPropagation:
pass

except BaseException:

date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
new = {
'error': str(sys.exc_info()[1]),
'date': datetime.datetime.now()
}

text = "**Sorry, my userbot encountered an error !!**\n"

link = "https://t.me/PaperplaneExtendedChat"

text += f"If you wanna you can report it - just forward this message [here]({link}).\n"
text += "Don't worry, this does not contain any sensitive data.\n"

ftext = "\nDisclaimer:\nThis file uploaded ONLY here, we logged only fact of error and date, "
ftext += "we respect your privacy, you may not report this error if you've "
ftext += "any confidential data here, no one will see your data.\n\n"

ftext += "--------BEGIN USERBOT TRACEBACK LOG--------"
ftext += "\nDate: " + date
ftext += "\nGroup ID: " + str(errors.chat_id)
ftext += "\nSender ID: " + str(errors.sender_id)
ftext += "\n\nEvent Trigger:\n"
ftext += str(errors.text)
ftext += "\n\nTraceback info:\n"
ftext += str(traceback.format_exc())
ftext += "\n\nError text:\n"
ftext += str(sys.exc_info()[1])
ftext += "\n\n--------END USERBOT TRACEBACK LOG--------"

command = "git log --pretty=format:\"%an: %s\" -5"

ftext += "\n\n\nLast 5 commits:\n"

process = await asyncio.create_subprocess_shell(
command,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
result = str(stdout.decode().strip()) \
+ str(stderr.decode().strip())

ftext += result

file = open("error.log", "w+")
file.write(ftext)
file.close()

await errors.client.send_file(
errors.chat_id,
"error.log",
caption=text,
)
return

return wrapper
return decorator
19 changes: 2 additions & 17 deletions userbot/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
MessageMediaPhoto)

from userbot import BOTLOG, BOTLOG_CHATID, CMD_HELP, bot
from userbot.events import register, errors_handler
from userbot.events import register

# =================== CONSTANT ===================
PP_TOO_SMOL = "`The image is too small`"
Expand Down Expand Up @@ -78,7 +78,6 @@
# ================================================

@register(outgoing=True, pattern="^.setgrouppic$")
@errors_handler
async def set_group_photo(gpic):
""" For .setgrouppic command, changes the picture of a group """
if not gpic.text[0].isalpha() and gpic.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -115,7 +114,6 @@ async def set_group_photo(gpic):


@register(outgoing=True, pattern="^.promote(?: |$)(.*)")
@errors_handler
async def promote(promt):
""" For .promote command, do promote targeted person """
if not promt.text[0].isalpha() \
Expand Down Expand Up @@ -176,7 +174,6 @@ async def promote(promt):


@register(outgoing=True, pattern="^.demote(?: |$)(.*)")
@errors_handler
async def demote(dmod):
""" For .demote command, do demote targeted person """
if not dmod.text[0].isalpha() and dmod.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -235,7 +232,6 @@ async def demote(dmod):


@register(outgoing=True, pattern="^.ban(?: |$)(.*)")
@errors_handler
async def ban(bon):
""" For .ban command, do "thanos" at targeted person """
if not bon.text[0].isalpha() and bon.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -295,7 +291,6 @@ async def ban(bon):


@register(outgoing=True, pattern="^.unban(?: |$)(.*)")
@errors_handler
async def nothanos(unbon):
""" For .unban command, undo "thanos" on target """
if not unbon.text[0].isalpha() and unbon.text[0] \
Expand Down Expand Up @@ -340,7 +335,6 @@ async def nothanos(unbon):


@register(outgoing=True, pattern="^.mute(?: |$)(.*)")
@errors_handler
async def spider(spdr):
"""
This function is basically muting peeps
Expand Down Expand Up @@ -406,7 +400,6 @@ async def spider(spdr):


@register(outgoing=True, pattern="^.unmute(?: |$)(.*)")
@errors_handler
async def unmoot(unmot):
""" For .unmute command, unmute the target """
if not unmot.text[0].isalpha() and unmot.text[0] \
Expand Down Expand Up @@ -464,7 +457,6 @@ async def unmoot(unmot):


@register(incoming=True)
@errors_handler
async def muter(moot):
""" Used for deleting the messages of muted people """
try:
Expand Down Expand Up @@ -499,7 +491,6 @@ async def muter(moot):


@register(outgoing=True, pattern="^.ungmute(?: |$)(.*)")
@errors_handler
async def ungmoot(un_gmute):
""" For .ungmute command, ungmutes the target in the userbot """
if not un_gmute.text[0].isalpha() and un_gmute.text[0] \
Expand Down Expand Up @@ -546,7 +537,6 @@ async def ungmoot(un_gmute):


@register(outgoing=True, pattern="^.gmute(?: |$)(.*)")
@errors_handler
async def gspider(gspdr):
""" For .gmute command, gmutes the target in the userbot """
if not gspdr.text[0].isalpha() and gspdr.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -591,7 +581,6 @@ async def gspider(gspdr):


@register(outgoing=True, pattern="^.delusers(?: |$)(.*)")
@errors_handler
async def rm_deletedacc(show):
""" For .adminlist command, list all of the admins of the chat. """
if not show.text[0].isalpha() and show.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -669,7 +658,6 @@ async def rm_deletedacc(show):


@register(outgoing=True, pattern="^.adminlist$")
@errors_handler
async def get_admin(show):
""" For .adminlist command, list all of the admins of the chat. """
if not show.text[0].isalpha() and show.text[0] not in ("/", "#", "@", "!"):
Expand All @@ -695,7 +683,6 @@ async def get_admin(show):


@register(outgoing=True, pattern="^.pin(?: |$)(.*)")
@errors_handler
async def pin(msg):
if not msg.text[0].isalpha() and msg.text[0] not in ("/", "#", "@", "!"):
# Admin or creator check
Expand Down Expand Up @@ -742,7 +729,6 @@ async def pin(msg):


@register(outgoing=True, pattern="^.kick(?: |$)(.*)")
@errors_handler
async def kick(usr):
""" For .kick command, kick someone from the group using the userbot. """
if not usr.text[0].isalpha() and usr.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -796,7 +782,6 @@ async def kick(usr):


@register(outgoing=True, pattern="^.userslist ?(.*)")
@errors_handler
async def get_users(show):
""" For .userslist command, list all of the users of the chat. """
if not show.text[0].isalpha() and show.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -903,4 +888,4 @@ async def get_user_from_id(user, event):
\nUsage: Retrieves all admins in the chat.\
\n\n.userslist or .userslist <name>\
\nUsage: Retrieves all users in the chat."
})
})
8 changes: 2 additions & 6 deletions userbot/modules/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from userbot import (COUNT_MSG, CMD_HELP, BOTLOG, BOTLOG_CHATID,
USERS)
from userbot.events import register, errors_handler
from userbot.events import register

from userbot.modules.sql_helper.globals import gvarstatus, addgvar, delgvar

Expand Down Expand Up @@ -45,7 +45,6 @@
]

@register(incoming=True, disable_edited=True)
@errors_handler
async def mention_afk(mention):
""" This function takes care of notifying the people who mention you that you are AFK."""
global COUNT_MSG
Expand Down Expand Up @@ -83,7 +82,6 @@ async def mention_afk(mention):


@register(incoming=True, disable_edited=True)
@errors_handler
async def afk_on_pm(sender):
""" Function which informs people that you are AFK in PM """
ISAFK = gvarstatus("AFK_STATUS")
Expand Down Expand Up @@ -121,7 +119,6 @@ async def afk_on_pm(sender):


@register(outgoing=True, pattern="^.afk(?: |$)(.*)")
@errors_handler
async def set_afk(afk_e):
""" For .afk command, allows you to inform people that you are afk when they message you """
if not afk_e.text[0].isalpha() and afk_e.text[0] not in ("/", "#", "@", "!"):
Expand All @@ -141,7 +138,6 @@ async def set_afk(afk_e):


@register(outgoing=True)
@errors_handler
async def type_afk_is_not_true(notafk):
""" This sets your status as not afk automatically when you write something while being afk """
ISAFK = gvarstatus("AFK_STATUS")
Expand Down Expand Up @@ -192,4 +188,4 @@ async def type_afk_is_not_true(notafk):
\nUsage: Sets you as afk.\nReplies to anyone who tags/PM's \
you telling them that you are AFK(reason).\n\nSwitches off AFK when you type back anything.\
"
})
})
9 changes: 2 additions & 7 deletions userbot/modules/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from bs4 import BeautifulSoup

from userbot import CMD_HELP
from userbot.events import register, errors_handler
from userbot.events import register


GITHUB = 'https://github.com'
Expand All @@ -20,7 +20,6 @@


@register(outgoing=True, pattern="^.magisk$")
@errors_handler
async def magisk(request):
""" magisk latest releases """
if not request.text[0].isalpha(
Expand All @@ -47,7 +46,6 @@ async def magisk(request):


@register(outgoing=True, pattern=r"^.device(?: |$)(\S*)")
@errors_handler
async def device_info(request):
""" get android device basic info from its codename """
if not request.text[0].isalpha()\
Expand Down Expand Up @@ -79,7 +77,6 @@ async def device_info(request):


@register(outgoing=True, pattern=r"^.codename(?: |)([\S]*)(?: |)([\s\S]*)")
@errors_handler
async def codename_info(request):
""" search for android codename """
if not request.text[0].isalpha()\
Expand Down Expand Up @@ -113,7 +110,6 @@ async def codename_info(request):


@register(outgoing=True, pattern=r"^.specs(?: |)([\S]*)(?: |)([\s\S]*)")
@errors_handler
async def devices_specifications(request):
""" Mobile devices specifications """
if not request.text[0].isalpha(
Expand Down Expand Up @@ -162,7 +158,6 @@ async def devices_specifications(request):


@register(outgoing=True, pattern=r"^.twrp(?: |$)(\S*)")
@errors_handler
async def twrp(request):
""" get android device twrp """
if not request.text[0].isalpha()\
Expand Down Expand Up @@ -206,4 +201,4 @@ async def twrp(request):
})
CMD_HELP.update({
"twrp": ".twrp <codename>\nUsage: Get latest twrp download for android device."
})
})
Loading

0 comments on commit b8cb321

Please sign in to comment.