Add missing defconfig

This commit is contained in:
2023-07-25 00:35:27 +02:00
parent bd12ea209e
commit aeb981629e
4 changed files with 86 additions and 27 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
StartWinDog StartWinDog
Database.json Database.json
Dump.txt Dump.txt
Config.py /Config.py
*.pyc *.pyc

21
LibWinDog/Config.py Normal file
View File

@ -0,0 +1,21 @@
# ================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ================================== #
MastodonUrl = ''
MastodonToken = ''
TGID = 1637713483
TGToken = ''
TGAdmins = [ 123456789, ]
TGWhitelist = [ 123456789, ]
TGRestrict = False
DefaultLang = 'en'
Debug = False
Dumper = False
CmdPrefixes = '.!/'
# False: ASCII output; True: ANSI Output (must be escaped)
ExecAllowed = {'date': False, 'fortune': False, 'neofetch': True, 'uptime': False}
WebUserAgent = f'WinDog v.Staging'

View File

@ -3,6 +3,8 @@
# Licensed under AGPLv3 by OctoSpacc # # Licensed under AGPLv3 by OctoSpacc #
# ================================== # # ================================== #
# Module: Percenter
# Provides fun trough percentage-based toys.
def percenter(Context, Data=None) -> None: def percenter(Context, Data=None) -> None:
if Data.Body: if Data.Body:
Text = choice(Locale.__(f'{Data.Name}.done')) Text = choice(Locale.__(f'{Data.Name}.done'))
@ -10,6 +12,8 @@ def percenter(Context, Data=None) -> None:
Text = choice(Locale.__(f'{Data.Name}.empty')) Text = choice(Locale.__(f'{Data.Name}.empty'))
SendMsg(Context, {"Text": Text.format(Cmd=Data.Tokens[0], Percent=RandPercent(), Thing=Data.Body)}) SendMsg(Context, {"Text": Text.format(Cmd=Data.Tokens[0], Percent=RandPercent(), Thing=Data.Body)})
# Module: Multifun
# Provides fun trough preprogrammed-text-based toys.
def multifun(update:Update, context:CallbackContext) -> None: def multifun(update:Update, context:CallbackContext) -> None:
Cmd = HandleCmd(update) Cmd = HandleCmd(update)
if not Cmd: return if not Cmd: return
@ -33,6 +37,8 @@ def multifun(update:Update, context:CallbackContext) -> None:
Text = CharEscape(choice(Locale.__(f'{Key}.empty')), 'MARKDOWN_SPEECH') Text = CharEscape(choice(Locale.__(f'{Key}.empty')), 'MARKDOWN_SPEECH')
update.message.reply_markdown_v2(Text, reply_to_message_id=ReplyToMsg) update.message.reply_markdown_v2(Text, reply_to_message_id=ReplyToMsg)
# Module: Start
# ...
def cStart(Context, Data=None) -> None: def cStart(Context, Data=None) -> None:
SendMsg(Context, {"Text": choice(Locale.__('start')).format('stupid')}) SendMsg(Context, {"Text": choice(Locale.__('start')).format('stupid')})
@ -45,17 +51,18 @@ def cStart(Context, Data=None) -> None:
# CharEscape(choice(Locale.__('start')), '.!').format(user.mention_markdown_v2()), # CharEscape(choice(Locale.__('start')), '.!').format(user.mention_markdown_v2()),
# reply_to_message_id=update.message.message_id) # reply_to_message_id=update.message.message_id)
def cHelp(update:Update, context:CallbackContext) -> None: # Module: Help
Cmd = HandleCmd(update) # ...
if not Cmd: return def cHelp(Context, Data=None) -> None:
update.message.reply_markdown_v2( SendMsg(Context, {"Text": choice(Locale.__('help'))})
CharEscape(choice(Locale.__('help')), 'MARKDOWN_SPEECH'),
reply_to_message_id=update.message.message_id)
def cSource(update:Update, context:CallbackContext) -> None: # Module: Source
Cmd = HandleCmd(update) # Provides a copy of the bot source codes and/or instructions on how to get it.
if not Cmd: return def cSource(Context, Data=None) -> None:
pass
# Module: Config
# ...
def cConfig(update:Update, context:CallbackContext) -> None: def cConfig(update:Update, context:CallbackContext) -> None:
Cmd = HandleCmd(update) Cmd = HandleCmd(update)
if not Cmd: return if not Cmd: return
@ -63,9 +70,13 @@ def cConfig(update:Update, context:CallbackContext) -> None:
# ... language: en, it, ... # ... language: en, it, ...
# ... userdata: import, export, delete # ... userdata: import, export, delete
# Module: Ping
# Responds pong, useful for testing messaging latency.
def cPing(Context, Data=None) -> None: def cPing(Context, Data=None) -> None:
SendMsg(Context, {"Text": "*Pong!*"}) SendMsg(Context, {"Text": "*Pong!*"})
# Module: Echo
# Responds back with the original text of the received message.
def cEcho(Context, Data=None) -> None: def cEcho(Context, Data=None) -> None:
if Data.Body: if Data.Body:
SendMsg(Context, {"Text": Data.Body}) SendMsg(Context, {"Text": Data.Body})
@ -77,6 +88,8 @@ def cEcho(Context, Data=None) -> None:
# CharEscape(choice(Locale.__('time')).format(time.ctime().replace(' ', ' ')), 'MARKDOWN_SPEECH'), # CharEscape(choice(Locale.__('time')).format(time.ctime().replace(' ', ' ')), 'MARKDOWN_SPEECH'),
# reply_to_message_id=update.message.message_id) # reply_to_message_id=update.message.message_id)
# Module: Hash
# Responds with the hash-sum of a message received.
def cHash(Context, Data=None) -> None: def cHash(Context, Data=None) -> None:
if len(Data.Tokens) >= 3 and Data.Tokens[1] in hashlib.algorithms_available: if len(Data.Tokens) >= 3 and Data.Tokens[1] in hashlib.algorithms_available:
Alg = Data.Tokens[1] Alg = Data.Tokens[1]
@ -84,13 +97,13 @@ def cHash(Context, Data=None) -> None:
else: else:
SendMsg(Context, {"Text": choice(Locale.__('hash.usage')).format(Data.Tokens[0], hashlib.algorithms_available)}) SendMsg(Context, {"Text": choice(Locale.__('hash.usage')).format(Data.Tokens[0], hashlib.algorithms_available)})
def cEval(update:Update, context:CallbackContext) -> None: # Module: Eval
Cmd = HandleCmd(update) # Execute a Python command (or safe literal operation) in the current context.
if not Cmd: return def cEval(Context, Data=None) -> None:
update.message.reply_markdown_v2( SendMsg(Context, {"Text": choice(Locale.__('eval'))})
CharEscape(choice(Locale.__('eval')), 'MARKDOWN_SPEECH'),
reply_to_message_id=update.message.message_id)
# Module: Exec
# Execute a system command and return stdout/stderr.
def cExec(update:Update, context:CallbackContext) -> None: def cExec(update:Update, context:CallbackContext) -> None:
Cmd = HandleCmd(update) Cmd = HandleCmd(update)
if not Cmd: return if not Cmd: return
@ -106,14 +119,25 @@ def cExec(update:Update, context:CallbackContext) -> None:
CharEscape(choice(Locale.__('eval')), 'MARKDOWN_SPEECH'), CharEscape(choice(Locale.__('eval')), 'MARKDOWN_SPEECH'),
reply_to_message_id=update.message.message_id) reply_to_message_id=update.message.message_id)
# Module: Format
# Reformat text using an handful of rules
def cFormat(Context, Data=None) -> None:
pass
# Module: Frame
# Frame someone's message into a platform-styled image.
def cFrame(Context, Data=None) -> None:
pass
# Module: Web
# Provides results of a DuckDuckGo search.
# This is now broken with the new infer escape system... # This is now broken with the new infer escape system...
def cWeb(Context, Data=None) -> None: def cWeb(Context, Data=None) -> None:
if Data.Body: if Data.Body:
try: try:
QueryUrl = UrlParse.quote(Data.Body) QueryUrl = UrlParse.quote(Data.Body)
Req = HttpGet(f'https://html.duckduckgo.com/html?q={QueryUrl}') Req = HttpGet(f'https://html.duckduckgo.com/html?q={QueryUrl}')
#Caption = f'[🦆🔎 "*{CharEscape(Data.Body, "MARKDOWN")}*"](https://duckduckgo.com/?q={CharEscape(QueryUrl, "MARKDOWN")})\n\n' Caption = f'🦆🔎 "*{Data.Body}*": https://duckduckgo.com/?q={QueryUrl}\n\n'
Caption = f'[🦆🔎 "*{Data.Body}*"](https://duckduckgo.com/?q={QueryUrl})\n\n'
Index = 0 Index = 0
for Line in Req.read().decode().replace('\t', ' ').splitlines(): for Line in Req.read().decode().replace('\t', ' ').splitlines():
if ' class="result__a" ' in Line and ' href="//duckduckgo.com/l/?uddg=' in Line: if ' class="result__a" ' in Line and ' href="//duckduckgo.com/l/?uddg=' in Line:
@ -121,11 +145,15 @@ def cWeb(Context, Data=None) -> None:
Link = UrlParse.unquote(Line.split(' href="//duckduckgo.com/l/?uddg=')[1].split('&rut=')[0]) Link = UrlParse.unquote(Line.split(' href="//duckduckgo.com/l/?uddg=')[1].split('&rut=')[0])
Title = HtmlUnescape(Line.split('</a>')[0].split('</span>')[-1].split('>')[1]) Title = HtmlUnescape(Line.split('</a>')[0].split('</span>')[-1].split('>')[1])
Domain = Link.split('://')[1].split('/')[0] Domain = Link.split('://')[1].split('/')[0]
Caption += f'{Index}&period; {Title} --- {Link} --- `{Domain}`\n\n' Caption += f'{Index}&period; *{HtmlEscapeFull(Title)}*: {Link} &#91;`{Domain}`&#93;\n\n'
SendMsg(Context, {"Text": Caption}) SendMsg(Context, {"Text": f'{Caption}...'})
except Exception: except Exception:
raise raise
else:
pass
# Module: Translate
# Return the received message after translating it in another language.
def cTranslate(Context, Data=None) -> None: def cTranslate(Context, Data=None) -> None:
if Data.Body: if Data.Body:
try: try:
@ -138,6 +166,8 @@ def cTranslate(Context, Data=None) -> None:
else: else:
pass pass
# Module: Unsplash
# Send a picture sourced from Unsplash.
def cUnsplash(Context, Data=None) -> None: def cUnsplash(Context, Data=None) -> None:
try: try:
Req = HttpGet(f'https://source.unsplash.com/random/?{UrlParse.quote(Data.Body)}') Req = HttpGet(f'https://source.unsplash.com/random/?{UrlParse.quote(Data.Body)}')
@ -145,6 +175,8 @@ def cUnsplash(Context, Data=None) -> None:
except Exception: except Exception:
raise raise
# Module: Safebooru
# Send a picture sourced from Safebooru.
def cSafebooru(Context, Data=None) -> None: def cSafebooru(Context, Data=None) -> None:
ApiUrl = 'https://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags=' ApiUrl = 'https://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags='
try: try:

View File

@ -5,6 +5,7 @@
# ================================== # # ================================== #
import json, hashlib, re, time, subprocess import json, hashlib, re, time, subprocess
from binascii import hexlify
from magic import Magic from magic import Magic
from os import listdir from os import listdir
from os.path import isfile from os.path import isfile
@ -36,9 +37,9 @@ for Dir in ('Lib', 'Mod'):
Endpoints = { Endpoints = {
"start": cStart, "start": cStart,
#"help": cHelp, "help": cHelp,
#"config": cConfig, #"config": cConfig,
#"source": cSource, "source": cSource,
"ping": cPing, "ping": cPing,
"echo": cEcho, "echo": cEcho,
"wish": percenter, "wish": percenter,
@ -51,8 +52,10 @@ Endpoints = {
#"hands": multifun, #"hands": multifun,
#"sessocto": multifun, #"sessocto": multifun,
"hash": cHash, "hash": cHash,
#"eval": cEval, "eval": cEval,
#"exec": cExec, #"exec": cExec,
"format": cFormat,
"frame": cFrame,
"web": cWeb, "web": cWeb,
"translate": cTranslate, "translate": cTranslate,
"unsplash": cUnsplash, "unsplash": cUnsplash,
@ -131,6 +134,13 @@ def MarkdownCode(Text:str, Block:bool) -> str:
def MdToTxt(Md:str) -> str: def MdToTxt(Md:str) -> str:
return BeautifulSoup(markdown(Md), 'html.parser').get_text(' ') return BeautifulSoup(markdown(Md), 'html.parser').get_text(' ')
def HtmlEscapeFull(Raw:str) -> str:
New = ''
Hex = hexlify(Raw.encode()).decode()
for i in range(0, len(Hex), 2):
New += f'&#x{Hex[i] + Hex[i+1]};'
return New
def CmdAllowed(update) -> bool: def CmdAllowed(update) -> bool:
if not TGRestrict: if not TGRestrict:
return True return True
@ -262,12 +272,8 @@ def Main() -> None:
updater = Updater(TGToken) updater = Updater(TGToken)
dispatcher = updater.dispatcher dispatcher = updater.dispatcher
#dispatcher.add_handler(CommandHandler('start', cStart))
dispatcher.add_handler(CommandHandler('config', cConfig)) dispatcher.add_handler(CommandHandler('config', cConfig))
dispatcher.add_handler(CommandHandler('help', cHelp))
dispatcher.add_handler(CommandHandler('source', cSource))
#dispatcher.add_handler(CommandHandler('time', cTime)) #dispatcher.add_handler(CommandHandler('time', cTime))
dispatcher.add_handler(CommandHandler('eval', cEval))
dispatcher.add_handler(CommandHandler('exec', cExec)) dispatcher.add_handler(CommandHandler('exec', cExec))
for Cmd in ('hug', 'pat', 'poke', 'cuddle', 'floor', 'hands', 'sessocto'): for Cmd in ('hug', 'pat', 'poke', 'cuddle', 'floor', 'hands', 'sessocto'):