FireBot/config.py

77 lines
2.5 KiB
Python
Raw Normal View History

2023-11-06 00:51:42 +00:00
#!/usr/bin/python3
2023-11-07 12:51:55 +00:00
from os import environ as env
2023-11-24 19:09:46 +00:00
from dotenv import load_dotenv # type: ignore
2023-11-09 03:20:50 +00:00
import re, codecs
2023-11-15 04:34:01 +00:00
from typing import Optional, Any
import bare
2023-11-08 02:30:35 +00:00
2023-11-07 12:51:55 +00:00
load_dotenv()
2023-11-13 22:27:20 +00:00
__version__ = "v2.0.4"
2023-11-18 01:11:08 +00:00
npbase: str = "\[\x0303last\.fm\x03\] [A-Za-z0-9_[\]{}\\|\-^]{1,$MAX} (is listening|last listened) to: \x02.+ - .*\x02( \([0-9]+ plays\)( \[.*\])?)?"
2023-11-09 03:41:07 +00:00
su = "^(su|sudo|(su .*|sudo .*))$"
2023-11-09 03:20:50 +00:00
servers: dict[str, dict[str, Any]] = {
2023-11-06 00:51:42 +00:00
"ircnow": {
"address": "localhost",
"port": 6601,
"interval": 200,
"pass": env["ircnow_pass"],
"channels": {"#random": 0, "#dice": 0, "#offtopic": 0, "#main/replirc": 0},
"admins": [],
2023-11-15 04:39:02 +00:00
"hosts": ["9pfs.repl.co"],
2023-11-06 00:51:42 +00:00
},
"efnet": {
"address": "irc.mzima.net",
"channels": {"#random": 0, "#dice": 0},
"admins": [],
"hosts": ["154.sub-174-251-241.myvzw.com"],
2023-11-06 00:51:42 +00:00
},
"replirc": {
"address": "localhost",
"pass": env["replirc_pass"],
"channels": {"#random": 0, "#dice": 0, "#main": 0, "#bots": 0, "#firebot": 0},
2023-11-15 05:06:49 +00:00
"admins": ["h-tl"],
2023-11-15 04:38:41 +00:00
"hosts": ["owner.firepi"],
2023-11-06 00:51:42 +00:00
},
2023-11-13 22:27:20 +00:00
"backupbox": {
"address": "172.23.11.5",
"channels": {"#default": 0, "#botrebellion": 0, "#main/replirc": 0},
2023-11-15 04:36:55 +00:00
"admins": [],
"hosts": ["172.20.171.225", "169.254.253.107"],
2023-11-15 05:26:02 +00:00
},
2023-11-06 00:51:42 +00:00
}
2023-11-15 04:39:02 +00:00
admin_hosts: list[str] = ["firepup.firepi", "47.221.227.180"]
2023-11-07 13:25:53 +00:00
ESCAPE_SEQUENCE_RE = re.compile(
r"""
( \\U........ # 8-digit hex escapes
| \\u.... # 4-digit hex escapes
| \\x.. # 2-digit hex escapes
| \\[0-7]{1,3} # Octal escapes
| \\N\{[^}]+\} # Unicode characters by name
| \\[\\'"abfnrtv] # Single-character escapes
)""",
re.UNICODE | re.VERBOSE,
)
2023-11-07 13:53:14 +00:00
prefix = "."
2023-11-08 02:30:35 +00:00
2023-11-07 13:53:14 +00:00
def decode_escapes(s: str) -> str:
def decode_match(match):
return codecs.decode(match.group(0), "unicode-escape")
return ESCAPE_SEQUENCE_RE.sub(decode_match, s)
2023-11-09 03:20:50 +00:00
def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
if usePrefix:
return any(message[: len(match) + 1] == prefix + match for match in find)
else:
return any(message[: len(match)] == match for match in find)
2023-11-24 07:15:33 +00:00
def sub(message: str, bot: bare.bot, chan: Optional[str], name: Optional[str]):
result = message.replace("$BOTNICK", bot.nick).replace("$NICK", bot.nick)
if chan:
result = result.replace("$CHANNEL", chan).replace("$CHAN", chan)
if name:
result = result.replace("$SENDER", name).replace("$NAME", name)
return result