mirror of https://xfnw.ttm.sh/git/oirc.git
reformat with black
This commit is contained in:
parent
ce7f30ac66
commit
3a3519764a
89
bot.py
89
bot.py
|
@ -10,105 +10,115 @@ from ircrobots import ConnectionParams, SASLUserPass, SASLSCRAM
|
||||||
from auth import username, password
|
from auth import username, password
|
||||||
import shared
|
import shared
|
||||||
|
|
||||||
|
|
||||||
def is_admin(func):
|
def is_admin(func):
|
||||||
async def decorator(self,channel,nick,msg):
|
async def decorator(self, channel, nick, msg):
|
||||||
if nick.lower() in self.users and self.users[nick.lower()].account in self.admins:
|
if (
|
||||||
await func(self,channel,nick,msg)
|
nick.lower() in self.users
|
||||||
|
and self.users[nick.lower()].account in self.admins
|
||||||
|
):
|
||||||
|
await func(self, channel, nick, msg)
|
||||||
else:
|
else:
|
||||||
await message(self,channel,'you do not have permission to do that')
|
await message(self, channel, "you do not have permission to do that")
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
#def is_chanop(func):
|
|
||||||
|
# def is_chanop(func):
|
||||||
|
|
||||||
|
|
||||||
def command(commandname):
|
def command(commandname):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
shared.commands[commandname] = func
|
shared.commands[commandname] = func
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def listener(listenername):
|
def listener(listenername):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
shared.listeners.append((listenername, func))
|
shared.listeners.append((listenername, func))
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def rawm(rname):
|
def rawm(rname):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
shared.rawm[rname] = func
|
shared.rawm[rname] = func
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
async def message(self, channel, msg):
|
||||||
async def message(self,channel,msg):
|
|
||||||
modname = os.path.splitext(os.path.basename(inspect.stack()[1].filename))[0]
|
modname = os.path.splitext(os.path.basename(inspect.stack()[1].filename))[0]
|
||||||
await self.send(build("PRIVMSG",[channel,f'[\x036{modname}\x0f] {msg}']))
|
await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Server(BaseServer):
|
class Server(BaseServer):
|
||||||
async def line_read(self, line: Line):
|
async def line_read(self, line: Line):
|
||||||
if 'on_'+line.command.lower() in dir(self):
|
if "on_" + line.command.lower() in dir(self):
|
||||||
asyncio.create_task(self.__getattribute__('on_'+line.command.lower())(line))
|
asyncio.create_task(
|
||||||
|
self.__getattribute__("on_" + line.command.lower())(line)
|
||||||
|
)
|
||||||
for listener in shared.listeners:
|
for listener in shared.listeners:
|
||||||
if listener[0] == line.command:
|
if listener[0] == line.command:
|
||||||
asyncio.create_task(listener[1](self,line))
|
asyncio.create_task(listener[1](self, line))
|
||||||
|
|
||||||
async def line_preread(self, line: Line):
|
async def line_preread(self, line: Line):
|
||||||
print(f"{self.name} < {line.format()}")
|
print(f"{self.name} < {line.format()}")
|
||||||
|
|
||||||
async def line_presend(self, line: Line):
|
async def line_presend(self, line: Line):
|
||||||
print(f"{self.name} > {line.format()}")
|
print(f"{self.name} > {line.format()}")
|
||||||
|
|
||||||
|
|
||||||
async def on_001(self, line):
|
async def on_001(self, line):
|
||||||
asyncio.create_task(self.load_modules())
|
asyncio.create_task(self.load_modules())
|
||||||
|
|
||||||
|
|
||||||
async def load_modules(self):
|
async def load_modules(self):
|
||||||
for i in [s for s in os.listdir('modules') if '.py' in s and '.swp' not in s]:
|
for i in [s for s in os.listdir("modules") if ".py" in s and ".swp" not in s]:
|
||||||
i = i[:-3]
|
i = i[:-3]
|
||||||
m = importlib.import_module('modules.' + i)
|
m = importlib.import_module("modules." + i)
|
||||||
asyncio.create_task(m.init(self))
|
asyncio.create_task(m.init(self))
|
||||||
shared.modules[i] = m
|
shared.modules[i] = m
|
||||||
|
|
||||||
# depricated, to support old modules
|
# depricated, to support old modules
|
||||||
async def message(self,channel,msg):
|
async def message(self, channel, msg):
|
||||||
await self.send(build("PRIVMSG",[channel,msg]))
|
await self.send(build("PRIVMSG", [channel, msg]))
|
||||||
|
|
||||||
|
|
||||||
async def on_privmsg(self, line):
|
async def on_privmsg(self, line):
|
||||||
if line.tags and "batch" in line.tags and line.tags["batch"] == '1':
|
if line.tags and "batch" in line.tags and line.tags["batch"] == "1":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
channel = line.params[0]
|
channel = line.params[0]
|
||||||
nick = line.source.split('!')[0]
|
nick = line.source.split("!")[0]
|
||||||
msg = line.params[1]
|
msg = line.params[1]
|
||||||
|
|
||||||
if channel == self.nickname:
|
if channel == self.nickname:
|
||||||
channel = nick
|
channel = nick
|
||||||
|
|
||||||
await self.handle_rawm(channel,nick,msg)
|
await self.handle_rawm(channel, nick, msg)
|
||||||
await self.handle_command(channel,nick,msg)
|
await self.handle_command(channel, nick, msg)
|
||||||
async def handle_rawm(self,channel,nick,msg):
|
|
||||||
|
async def handle_rawm(self, channel, nick, msg):
|
||||||
for i in shared.rawm:
|
for i in shared.rawm:
|
||||||
await shared.rawm[i](self,channel,nick,msg)
|
await shared.rawm[i](self, channel, nick, msg)
|
||||||
async def handle_command(self,channel,nick,msg):
|
|
||||||
if msg[:len(shared.prefix)] == shared.prefix:
|
async def handle_command(self, channel, nick, msg):
|
||||||
msg = msg[len(shared.prefix):]
|
if msg[: len(shared.prefix)] == shared.prefix:
|
||||||
cmd = msg.split(' ')[0]
|
msg = msg[len(shared.prefix) :]
|
||||||
msg = msg[len(cmd)+1:]
|
cmd = msg.split(" ")[0]
|
||||||
|
msg = msg[len(cmd) + 1 :]
|
||||||
if len(cmd) < 1:
|
if len(cmd) < 1:
|
||||||
return
|
return
|
||||||
|
|
||||||
if cmd in shared.commands:
|
if cmd in shared.commands:
|
||||||
await shared.commands[cmd](self,channel,nick,msg)
|
await shared.commands[cmd](self, channel, nick, msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
results = [i for i in shared.commands if i.startswith(cmd)]
|
results = [i for i in shared.commands if i.startswith(cmd)]
|
||||||
if len(results) == 1:
|
if len(results) == 1:
|
||||||
await shared.commands[results[0]](self,channel,nick,msg)
|
await shared.commands[results[0]](self, channel, nick, msg)
|
||||||
|
|
||||||
|
|
||||||
class Bot(BaseBot):
|
class Bot(BaseBot):
|
||||||
|
@ -120,16 +130,13 @@ async def main():
|
||||||
bot = Bot()
|
bot = Bot()
|
||||||
|
|
||||||
sasl_params = SASLUserPass(username, password)
|
sasl_params = SASLUserPass(username, password)
|
||||||
params = ConnectionParams(
|
params = ConnectionParams(
|
||||||
"balun",
|
"balun", host="irc.tilde.chat", port=6697, tls=True, sasl=sasl_params
|
||||||
host = "irc.tilde.chat",
|
)
|
||||||
port = 6697,
|
|
||||||
tls = True,
|
|
||||||
sasl = sasl_params)
|
|
||||||
|
|
||||||
await bot.add_server("tilde", params)
|
await bot.add_server("tilde", params)
|
||||||
await bot.run()
|
await bot.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|
37
lib/marx.py
37
lib/marx.py
|
@ -9,9 +9,9 @@ from typing import Dict, List, Optional, Pattern, Tuple
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from async_timeout import timeout as timeout_
|
from async_timeout import timeout as timeout_
|
||||||
from OpenSSL import crypto
|
from OpenSSL import crypto
|
||||||
|
|
||||||
#from .config import CertPattern
|
# from .config import CertPattern
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -20,25 +20,20 @@ class CertPattern(object):
|
||||||
find: List[Pattern]
|
find: List[Pattern]
|
||||||
|
|
||||||
|
|
||||||
|
CERT_KEYS = [("CN", "cn"), ("O", "on")]
|
||||||
CERT_KEYS = [
|
|
||||||
("CN", "cn"),
|
|
||||||
("O", "on")
|
|
||||||
]
|
|
||||||
|
|
||||||
TLS = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
TLS = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
||||||
|
|
||||||
|
|
||||||
def _bytes_dict(d: List[Tuple[bytes, bytes]]) -> Dict[str, str]:
|
def _bytes_dict(d: List[Tuple[bytes, bytes]]) -> Dict[str, str]:
|
||||||
return {k.decode("utf8"): v.decode("utf8") for k, v in d}
|
return {k.decode("utf8"): v.decode("utf8") for k, v in d}
|
||||||
|
|
||||||
|
|
||||||
class CertScanner(object):
|
class CertScanner(object):
|
||||||
def __init__(self, timeout: int = 5):
|
def __init__(self, timeout: int = 5):
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
|
|
||||||
async def _values(self,
|
async def _values(self, ip: str, port: int) -> List[Tuple[str, str]]:
|
||||||
ip: str,
|
|
||||||
port: int
|
|
||||||
) -> List[Tuple[str, str]]:
|
|
||||||
reader, writer = await asyncio.open_connection(ip, port, ssl=TLS)
|
reader, writer = await asyncio.open_connection(ip, port, ssl=TLS)
|
||||||
cert = writer.transport._ssl_protocol._sslpipe.ssl_object.getpeercert(True)
|
cert = writer.transport._ssl_protocol._sslpipe.ssl_object.getpeercert(True)
|
||||||
writer.close()
|
writer.close()
|
||||||
|
@ -47,7 +42,7 @@ class CertScanner(object):
|
||||||
x509 = crypto.load_certificate(crypto.FILETYPE_ASN1, cert)
|
x509 = crypto.load_certificate(crypto.FILETYPE_ASN1, cert)
|
||||||
|
|
||||||
subject = _bytes_dict(x509.get_subject().get_components())
|
subject = _bytes_dict(x509.get_subject().get_components())
|
||||||
issuer = _bytes_dict(x509.get_issuer().get_components())
|
issuer = _bytes_dict(x509.get_issuer().get_components())
|
||||||
|
|
||||||
values: List[Tuple[str, str]] = []
|
values: List[Tuple[str, str]] = []
|
||||||
for cert_key, match_key in CERT_KEYS:
|
for cert_key, match_key in CERT_KEYS:
|
||||||
|
@ -65,18 +60,14 @@ class CertScanner(object):
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
async def _match(
|
||||||
async def _match(self,
|
self, ip: str, port: int, certs: List[CertPattern]
|
||||||
ip: str,
|
) -> Optional[str]:
|
||||||
port: int,
|
|
||||||
certs: List[CertPattern]
|
|
||||||
) -> Optional[str]:
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with timeout_(self._timeout):
|
async with timeout_(self._timeout):
|
||||||
values_t = await self._values(ip, port)
|
values_t = await self._values(ip, port)
|
||||||
except (asyncio.TimeoutError,
|
except (asyncio.TimeoutError, ConnectionError):
|
||||||
ConnectionError):
|
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -89,10 +80,7 @@ class CertScanner(object):
|
||||||
return f"{value} (:{port} {cert.name})"
|
return f"{value} (:{port} {cert.name})"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def scan(self,
|
async def scan(self, ip: str, bad: Dict[int, List[CertPattern]]) -> Optional[str]:
|
||||||
ip: str,
|
|
||||||
bad: Dict[int, List[CertPattern]]
|
|
||||||
) -> Optional[str]:
|
|
||||||
coros = [self._match(ip, p, c) for p, c in bad.items()]
|
coros = [self._match(ip, p, c) for p, c in bad.items()]
|
||||||
tasks = set(asyncio.ensure_future(c) for c in coros)
|
tasks = set(asyncio.ensure_future(c) for c in coros)
|
||||||
while tasks:
|
while tasks:
|
||||||
|
@ -110,4 +98,3 @@ class CertScanner(object):
|
||||||
return result
|
return result
|
||||||
tasks = set(asyncio.ensure_future(f) for f in unfinished)
|
tasks = set(asyncio.ensure_future(f) for f in unfinished)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
301
modules/admin.py
301
modules/admin.py
|
@ -1,213 +1,260 @@
|
||||||
|
|
||||||
import importlib, time, asyncio, random
|
import importlib, time, asyncio, random
|
||||||
from bot import *
|
from bot import *
|
||||||
|
|
||||||
quitmessages = [
|
quitmessages = [
|
||||||
"time to die",
|
"time to die",
|
||||||
'you can hide, but you can not run!',
|
"you can hide, but you can not run!",
|
||||||
"you're next",
|
"you're next",
|
||||||
'bye',
|
"bye",
|
||||||
'the balun has been popped.',
|
"the balun has been popped.",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def commit(self, chan, source, msg):
|
async def commit(self, chan, source, msg):
|
||||||
await self.quit('{} told me to commit {}'.format(source,msg))
|
await self.quit("{} told me to commit {}".format(source, msg))
|
||||||
|
|
||||||
|
|
||||||
async def quit(self, chan, source, msg):
|
async def quit(self, chan, source, msg):
|
||||||
await self.send(build("QUIT",[random.choice(quitmessages)]))
|
await self.send(build("QUIT", [random.choice(quitmessages)]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def reloadmods(self, chan, source, msg):
|
async def reloadmods(self, chan, source, msg):
|
||||||
await self.message(chan, '[\x036admin\x0f] reloading modules...')
|
await self.message(chan, "[\x036admin\x0f] reloading modules...")
|
||||||
shared.oldcmd = shared.commands
|
shared.oldcmd = shared.commands
|
||||||
shared.commands = {}
|
shared.commands = {}
|
||||||
shared.rawm = {}
|
shared.rawm = {}
|
||||||
shared.listeners = []
|
shared.listeners = []
|
||||||
shared.help = {}
|
shared.help = {}
|
||||||
try:
|
try:
|
||||||
for i in shared.modules:
|
for i in shared.modules:
|
||||||
importlib.reload(shared.modules[i])
|
importlib.reload(shared.modules[i])
|
||||||
await shared.modules[i].init(self)
|
await shared.modules[i].init(self)
|
||||||
#await self.message(chan, '[\x036admin\x0f] load {} sucess!'.format(i))
|
# await self.message(chan, '[\x036admin\x0f] load {} sucess!'.format(i))
|
||||||
await self.message(chan, '[\x036admin\x0f] done! {} modules reloaded!'.format(len(shared.modules)))
|
await self.message(
|
||||||
except:
|
chan,
|
||||||
await self.message(chan, '[\x036admin\x0f] reload failed... attempting to recover...')
|
"[\x036admin\x0f] done! {} modules reloaded!".format(len(shared.modules)),
|
||||||
shared.commands = shared.oldcmd
|
)
|
||||||
|
except:
|
||||||
|
await self.message(
|
||||||
|
chan, "[\x036admin\x0f] reload failed... attempting to recover..."
|
||||||
|
)
|
||||||
|
shared.commands = shared.oldcmd
|
||||||
|
|
||||||
|
|
||||||
async def rawcmd(self, chan, source, msg):
|
async def rawcmd(self, chan, source, msg):
|
||||||
await self.send_raw(msg)
|
await self.send_raw(msg)
|
||||||
|
|
||||||
|
|
||||||
async def joins(self, chan, source, msg):
|
async def joins(self, chan, source, msg):
|
||||||
await self.message(chan, '[\x036admin\x0f] joining slowly as to not flood...')
|
await self.message(chan, "[\x036admin\x0f] joining slowly as to not flood...")
|
||||||
for i in self.chandb.all():
|
for i in self.chandb.all():
|
||||||
await self.send(build("JOIN",[i['name']]))
|
await self.send(build("JOIN", [i["name"]]))
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
print('joined {}'.format(i['name']))
|
print("joined {}".format(i["name"]))
|
||||||
await self.message(chan, '[\x036admin\x0f] Sucess! i may be laggy for a bit while i sort through all these channels...')
|
await self.message(
|
||||||
|
chan,
|
||||||
|
"[\x036admin\x0f] Sucess! i may be laggy for a bit while i sort through all these channels...",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def aexec(self, code):
|
async def aexec(self, code):
|
||||||
# Make an async function with the code and `exec` it
|
# Make an async function with the code and `exec` it
|
||||||
exec(
|
exec(f"async def __ex(self): " + "".join(f"\n {l}" for l in code.split("\n")))
|
||||||
f'async def __ex(self): ' +
|
|
||||||
''.join(f'\n {l}' for l in code.split('\n'))
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get `__ex` from local variables, call it and return the result
|
# Get `__ex` from local variables, call it and return the result
|
||||||
return await locals()['__ex'](self)
|
return await locals()["__ex"](self)
|
||||||
|
|
||||||
|
|
||||||
async def ev(self, chan, source, msg):
|
async def ev(self, chan, source, msg):
|
||||||
msg = msg.split(' ')
|
msg = msg.split(" ")
|
||||||
try:
|
try:
|
||||||
await self.message(chan, '[\x036admin\x0f] ok, output: {}'.format(
|
await self.message(
|
||||||
str(await aexec(self, ' '.join(msg)))[:400]
|
chan,
|
||||||
))
|
"[\x036admin\x0f] ok, output: {}".format(
|
||||||
except:
|
str(await aexec(self, " ".join(msg)))[:400]
|
||||||
await self.message(chan, '[\x036admin\x0f] exception in eval!')
|
),
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
await self.message(chan, "[\x036admin\x0f] exception in eval!")
|
||||||
|
|
||||||
|
|
||||||
async def send(self, c, n, m):
|
async def send(self, c, n, m):
|
||||||
msg = m.split(' ')
|
msg = m.split(" ")
|
||||||
await self.message(msg.pop(0), ' '.join(msg))
|
await self.message(msg.pop(0), " ".join(msg))
|
||||||
await self.message(c, '[\x036admin\x0f] sent')
|
await self.message(c, "[\x036admin\x0f] sent")
|
||||||
|
|
||||||
|
|
||||||
async def shut(self, c, n, m):
|
async def shut(self, c, n, m):
|
||||||
shared.qtime[c] = time.time()+(60*10)
|
shared.qtime[c] = time.time() + (60 * 10)
|
||||||
await self.message(c, '[\x036admin\x0f] Ok, il be back in 10 minutes')
|
await self.message(c, "[\x036admin\x0f] Ok, il be back in 10 minutes")
|
||||||
|
|
||||||
|
|
||||||
async def schans(self, c, n, m):
|
async def schans(self, c, n, m):
|
||||||
self.chandb.delete()
|
self.chandb.delete()
|
||||||
for i in self.channels:
|
for i in self.channels:
|
||||||
self.chandb.insert(dict(name=i))
|
self.chandb.insert(dict(name=i))
|
||||||
await self.message(c, '[\x036admin\x0f] Ok')
|
await self.message(c, "[\x036admin\x0f] Ok")
|
||||||
|
|
||||||
async def addalias(self,c,n,m):
|
|
||||||
al = m.split(' ')[0]
|
async def addalias(self, c, n, m):
|
||||||
m = m[len(al)+1:] # dont use the list since i want trailing spaces
|
al = m.split(" ")[0]
|
||||||
|
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
|
||||||
if al in self.cmd:
|
if al in self.cmd:
|
||||||
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
|
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
|
||||||
return
|
return
|
||||||
self.cmd[al]=Alias(m).alias
|
self.cmd[al] = Alias(m).alias
|
||||||
|
|
||||||
await self.message(c,'[\x036admin\x0f] added "{}" alias for "{}"'.format(al,m))
|
await self.message(c, '[\x036admin\x0f] added "{}" alias for "{}"'.format(al, m))
|
||||||
|
|
||||||
|
|
||||||
async def addot(self,c,n,m):
|
async def addot(self, c, n, m):
|
||||||
al = m.split(' ')[0]
|
al = m.split(" ")[0]
|
||||||
m = m[len(al)+1:] # dont use the list since i want trailing spaces
|
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
|
||||||
if al in shared.rawm:
|
if al in shared.rawm:
|
||||||
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
|
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
|
||||||
return
|
return
|
||||||
shared.rawm[al]=Ot(m,al).ot
|
shared.rawm[al] = Ot(m, al).ot
|
||||||
|
|
||||||
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
|
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
|
||||||
|
|
||||||
|
|
||||||
async def addspook(self,c,n,m):
|
async def addspook(self, c, n, m):
|
||||||
al = m.split(' ')[0]
|
al = m.split(" ")[0]
|
||||||
m = m[len(al)+1:] # dont use the list since i want trailing spaces
|
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
|
||||||
if al in shared.rawm:
|
if al in shared.rawm:
|
||||||
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
|
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
|
||||||
return
|
return
|
||||||
shared.rawm[al]=Spook(m,al).spook
|
shared.rawm[al] = Spook(m, al).spook
|
||||||
|
|
||||||
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
|
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
|
||||||
|
|
||||||
async def addtrigger(self,c,n,m):
|
|
||||||
al = m.split(' ')[0]
|
async def addtrigger(self, c, n, m):
|
||||||
m = m[len(al)+1:] # dont use the list since i want trailing spaces
|
al = m.split(" ")[0]
|
||||||
|
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
|
||||||
if al in shared.rawm:
|
if al in shared.rawm:
|
||||||
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
|
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
|
||||||
return
|
return
|
||||||
shared.rawm[al]=Trigger(m,al).trigger
|
shared.rawm[al] = Trigger(m, al).trigger
|
||||||
|
|
||||||
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
|
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
|
||||||
|
|
||||||
|
|
||||||
|
class Ot:
|
||||||
class Ot():
|
|
||||||
def __init__(self, ms, al):
|
def __init__(self, ms, al):
|
||||||
self.ms = str(ms)
|
self.ms = str(ms)
|
||||||
self.al = str(al)
|
self.al = str(al)
|
||||||
async def ot(alself,self,c,n,m):
|
|
||||||
|
async def ot(alself, self, c, n, m):
|
||||||
if alself.al in m and n != self.nickname:
|
if alself.al in m and n != self.nickname:
|
||||||
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
|
asyncio.create_task(
|
||||||
|
self.on_privmsg(
|
||||||
|
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
|
||||||
|
)
|
||||||
|
)
|
||||||
shared.rawm.pop(alself.al)
|
shared.rawm.pop(alself.al)
|
||||||
|
|
||||||
|
|
||||||
class Spook():
|
class Spook:
|
||||||
def __init__(self, ms, al):
|
def __init__(self, ms, al):
|
||||||
self.ms = str(ms)
|
self.ms = str(ms)
|
||||||
self.al = str(al)
|
self.al = str(al)
|
||||||
async def spook(alself,self,c,n,m):
|
|
||||||
|
async def spook(alself, self, c, n, m):
|
||||||
if alself.al in m and n != self.nickname:
|
if alself.al in m and n != self.nickname:
|
||||||
asyncio.create_task(self.message(c,alself.ms.format(m)))
|
asyncio.create_task(self.message(c, alself.ms.format(m)))
|
||||||
shared.rawm.pop(alself.al)
|
shared.rawm.pop(alself.al)
|
||||||
|
|
||||||
|
|
||||||
class Trigger():
|
class Trigger:
|
||||||
def __init__(self, ms, al):
|
def __init__(self, ms, al):
|
||||||
self.ms = str(ms)
|
self.ms = str(ms)
|
||||||
self.al = str(al)
|
self.al = str(al)
|
||||||
async def trigger(alself,self,c,n,m):
|
|
||||||
|
async def trigger(alself, self, c, n, m):
|
||||||
if alself.al in m:
|
if alself.al in m:
|
||||||
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
|
asyncio.create_task(
|
||||||
|
self.on_privmsg(
|
||||||
|
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Alias():
|
class Alias:
|
||||||
def __init__(self, ms):
|
def __init__(self, ms):
|
||||||
self.ms = str(ms)
|
self.ms = str(ms)
|
||||||
async def alias(alself,self,c,n,m):
|
|
||||||
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
|
|
||||||
|
|
||||||
|
async def alias(alself, self, c, n, m):
|
||||||
|
asyncio.create_task(
|
||||||
|
self.on_privmsg(
|
||||||
|
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
'quit': quit,
|
"quit": quit,
|
||||||
'reload': reloadmods,
|
"reload": reloadmods,
|
||||||
'commit': commit,
|
"commit": commit,
|
||||||
'raw': rawcmd,
|
"raw": rawcmd,
|
||||||
'eval': ev,
|
"eval": ev,
|
||||||
'send': send,
|
"send": send,
|
||||||
'joins': joins,
|
"joins": joins,
|
||||||
'shut': shut,
|
"shut": shut,
|
||||||
'schans': schans,
|
"schans": schans,
|
||||||
'addalias': addalias,
|
"addalias": addalias,
|
||||||
'addtrigger': addtrigger,
|
"addtrigger": addtrigger,
|
||||||
'addot': addot,
|
"addot": addot,
|
||||||
'addspook': addspook,
|
"addspook": addspook,
|
||||||
}
|
}
|
||||||
|
|
||||||
@command('admin')
|
|
||||||
|
@command("admin")
|
||||||
@is_admin
|
@is_admin
|
||||||
async def adminHandle(self, chan, source, msg):
|
async def adminHandle(self, chan, source, msg):
|
||||||
msg = msg.split(' ')
|
msg = msg.split(" ")
|
||||||
if len(msg) < 1 or not msg[0] in commands:
|
if len(msg) < 1 or not msg[0] in commands:
|
||||||
await self.message(chan, '[\x036admin\x0f] Invalid command')
|
await self.message(chan, "[\x036admin\x0f] Invalid command")
|
||||||
return
|
return
|
||||||
print('[ADMIN MODULE] {} told me to {}!!!'.format(source,msg[0]))
|
print("[ADMIN MODULE] {} told me to {}!!!".format(source, msg[0]))
|
||||||
asyncio.create_task(commands[msg.pop(0)](self, chan, source, ' '.join(msg)))
|
asyncio.create_task(commands[msg.pop(0)](self, chan, source, " ".join(msg)))
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.chandb = shared.db['chan']
|
self.chandb = shared.db["chan"]
|
||||||
|
|
||||||
self.admins = ['xfnw']
|
|
||||||
return
|
|
||||||
self.cmd['admin'] = adminHandle
|
|
||||||
|
|
||||||
self.help['admin'] = ['admin - various bot owner commands (more for subcommands)', 'sub-commands of admin, for more info do help admin <command>: quit reload commit part join joins eval send']
|
|
||||||
self.help['admin quit'] = ['admin quit <message> - make the bot disconnect','no']
|
|
||||||
self.help['admin reload'] = ['admin reload - reload the modules and configs', 'nothing to see here']
|
|
||||||
self.help['admin commit'] = ['admin commit <action> - oh no (more)', 'suggested with <3 by khux']
|
|
||||||
self.help['admin part'] = ['admin part <channel> - leave a channel', ':o']
|
|
||||||
self.help['admin join'] = ['admin join <channel> - make the bot join a channel','...']
|
|
||||||
self.help['admin joins'] = ['admin joins - join more channels', 'dont reconnect to a bunch of chans when the bots crashing etc']
|
|
||||||
self.help['admin eval'] = ['admin eval <command> - absolute power corrupts absolutely', 'lmao']
|
|
||||||
self.help['admin send'] = ['admin send <channel> <message> - send a message', 'lmao']
|
|
||||||
self.help['admin schans'] = ['admin schans - save the commands to join',';p;']
|
|
||||||
|
|
||||||
|
|
||||||
|
self.admins = ["xfnw"]
|
||||||
|
return
|
||||||
|
self.cmd["admin"] = adminHandle
|
||||||
|
|
||||||
|
self.help["admin"] = [
|
||||||
|
"admin - various bot owner commands (more for subcommands)",
|
||||||
|
"sub-commands of admin, for more info do help admin <command>: quit reload commit part join joins eval send",
|
||||||
|
]
|
||||||
|
self.help["admin quit"] = ["admin quit <message> - make the bot disconnect", "no"]
|
||||||
|
self.help["admin reload"] = [
|
||||||
|
"admin reload - reload the modules and configs",
|
||||||
|
"nothing to see here",
|
||||||
|
]
|
||||||
|
self.help["admin commit"] = [
|
||||||
|
"admin commit <action> - oh no (more)",
|
||||||
|
"suggested with <3 by khux",
|
||||||
|
]
|
||||||
|
self.help["admin part"] = ["admin part <channel> - leave a channel", ":o"]
|
||||||
|
self.help["admin join"] = [
|
||||||
|
"admin join <channel> - make the bot join a channel",
|
||||||
|
"...",
|
||||||
|
]
|
||||||
|
self.help["admin joins"] = [
|
||||||
|
"admin joins - join more channels",
|
||||||
|
"dont reconnect to a bunch of chans when the bots crashing etc",
|
||||||
|
]
|
||||||
|
self.help["admin eval"] = [
|
||||||
|
"admin eval <command> - absolute power corrupts absolutely",
|
||||||
|
"lmao",
|
||||||
|
]
|
||||||
|
self.help["admin send"] = [
|
||||||
|
"admin send <channel> <message> - send a message",
|
||||||
|
"lmao",
|
||||||
|
]
|
||||||
|
self.help["admin schans"] = ["admin schans - save the commands to join", ";p;"]
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
from bot import *
|
from bot import *
|
||||||
|
|
||||||
modulename='botlist'
|
modulename = "botlist"
|
||||||
|
|
||||||
@rawm('botlist')
|
|
||||||
async def botlist(s,c,n,m):
|
@rawm("botlist")
|
||||||
if m == '!botlist':
|
async def botlist(s, c, n, m):
|
||||||
await message(s,modulename,c,'hi im balun ; prefix . ; owner xfnw')
|
if m == "!botlist":
|
||||||
|
await message(s, modulename, c, "hi im balun ; prefix . ; owner xfnw")
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
await self.send(build("MODE",[self.nickname,'+B']))
|
await self.send(build("MODE", [self.nickname, "+B"]))
|
||||||
|
|
139
modules/coin.py
139
modules/coin.py
|
@ -5,49 +5,56 @@ from bot import *
|
||||||
async def bal(self):
|
async def bal(self):
|
||||||
bals = {}
|
bals = {}
|
||||||
for t in self.ledger:
|
for t in self.ledger:
|
||||||
await asyncio.sleep(0) # yeild control as this is a long operation
|
await asyncio.sleep(0) # yeild control as this is a long operation
|
||||||
t['amount'] = float(t['amount'])
|
t["amount"] = float(t["amount"])
|
||||||
if t['amount'] < 0.01:
|
if t["amount"] < 0.01:
|
||||||
self.ledger.delete(id=t['id'])
|
self.ledger.delete(id=t["id"])
|
||||||
continue # dont send negative money lol
|
continue # dont send negative money lol
|
||||||
if t['sender'] not in bals:
|
if t["sender"] not in bals:
|
||||||
bals[t['sender']]=0.00
|
bals[t["sender"]] = 0.00
|
||||||
if t['to'] not in bals:
|
if t["to"] not in bals:
|
||||||
bals[t['to']]=0.00
|
bals[t["to"]] = 0.00
|
||||||
|
|
||||||
if t['sender'] != 'bank' and round(bals[t['sender']],2) - t['amount'] < 0.0:
|
if t["sender"] != "bank" and round(bals[t["sender"]], 2) - t["amount"] < 0.0:
|
||||||
self.ledger.delete(id=t['id'])
|
self.ledger.delete(id=t["id"])
|
||||||
continue # no debt for you
|
continue # no debt for you
|
||||||
bals[t['sender']] += 0 - t['amount']
|
bals[t["sender"]] += 0 - t["amount"]
|
||||||
bals[t['to']] += t['amount']
|
bals[t["to"]] += t["amount"]
|
||||||
|
|
||||||
for i in bals:
|
for i in bals:
|
||||||
bals['bank'] += bals[i] * 0.001
|
bals["bank"] += bals[i] * 0.001
|
||||||
bals[i] -= bals[i] * 0.001
|
bals[i] -= bals[i] * 0.001
|
||||||
self.initfund = abs(bals['bank'])
|
self.initfund = abs(bals["bank"])
|
||||||
return bals
|
return bals
|
||||||
|
|
||||||
async def send(self,c,n,m):
|
|
||||||
m = m.split(' ')
|
async def send(self, c, n, m):
|
||||||
|
m = m.split(" ")
|
||||||
if len(m) < 2:
|
if len(m) < 2:
|
||||||
await self.message(c, '[\x036coin\x0f] invalid syntax')
|
await self.message(c, "[\x036coin\x0f] invalid syntax")
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
to = self.users[m.pop(0).lower()].account
|
to = self.users[m.pop(0).lower()].account
|
||||||
except:
|
except:
|
||||||
await self.message(c, '[\x036coin\x0f] that user is not logged in. refusing so coins are not lost')
|
await self.message(
|
||||||
if to == '':
|
c,
|
||||||
await self.message(c, '[\x036coin\x0f] they must authenticate with nickserv.')
|
"[\x036coin\x0f] that user is not logged in. refusing so coins are not lost",
|
||||||
|
)
|
||||||
|
if to == "":
|
||||||
|
await self.message(c, "[\x036coin\x0f] they must authenticate with nickserv.")
|
||||||
return
|
return
|
||||||
amount = round(float(m.pop(0)),2)
|
amount = round(float(m.pop(0)), 2)
|
||||||
message = ' '.join(m)
|
message = " ".join(m)
|
||||||
sender = self.users[n.lower()].account
|
sender = self.users[n.lower()].account
|
||||||
|
|
||||||
self.ledger.insert(dict(to=to,sender=sender,amount=amount,message=message))
|
self.ledger.insert(dict(to=to, sender=sender, amount=amount, message=message))
|
||||||
|
|
||||||
await self.message(c, '[\x036coin\x0f] added transaction to ledger, check balances to verify')
|
await self.message(
|
||||||
|
c, "[\x036coin\x0f] added transaction to ledger, check balances to verify"
|
||||||
|
)
|
||||||
|
|
||||||
async def balance(self,c,n,m):
|
|
||||||
|
async def balance(self, c, n, m):
|
||||||
m = m.strip()
|
m = m.strip()
|
||||||
if len(m) < 1:
|
if len(m) < 1:
|
||||||
m = n
|
m = n
|
||||||
|
@ -55,44 +62,68 @@ async def balance(self,c,n,m):
|
||||||
m = self.users[m.lower()].account
|
m = self.users[m.lower()].account
|
||||||
except:
|
except:
|
||||||
m = m
|
m = m
|
||||||
if m == '':
|
if m == "":
|
||||||
m = m
|
m = m
|
||||||
bals = await bal(self)
|
bals = await bal(self)
|
||||||
if m in bals:
|
if m in bals:
|
||||||
latest = self.ledger.find_one(to=m,order_by='-id')
|
latest = self.ledger.find_one(to=m, order_by="-id")
|
||||||
if latest:
|
if latest:
|
||||||
await self.message(c, '[\x036coin\x0f] {}\u200c{}\'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply'
|
await self.message(
|
||||||
.format(m[:1],m[1:],round(bals[m],2),int((bals[m]/self.initfund)*100))+
|
c,
|
||||||
'. last deposit: [{} from {}, "{}"]'.format(
|
"[\x036coin\x0f] {}\u200c{}'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply".format(
|
||||||
latest['amount'], latest['sender'], latest['message']
|
m[:1],
|
||||||
))
|
m[1:],
|
||||||
|
round(bals[m], 2),
|
||||||
|
int((bals[m] / self.initfund) * 100),
|
||||||
|
)
|
||||||
|
+ '. last deposit: [{} from {}, "{}"]'.format(
|
||||||
|
latest["amount"], latest["sender"], latest["message"]
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.message(c, '[\x036coin\x0f] {}\u200c{}\'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply'
|
await self.message(
|
||||||
.format(m[:1],m[1:],round(bals[m],2),int((bals[m]/self.initfund)*100)))
|
c,
|
||||||
|
"[\x036coin\x0f] {}\u200c{}'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply".format(
|
||||||
|
m[:1],
|
||||||
|
m[1:],
|
||||||
|
round(bals[m], 2),
|
||||||
|
int((bals[m] / self.initfund) * 100),
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.message(c, '[\x036coin\x0f] this user has never made a transaction')
|
await self.message(c, "[\x036coin\x0f] this user has never made a transaction")
|
||||||
|
|
||||||
async def richest(self,c,n,m):
|
|
||||||
richest = sorted((await bal(self)).items(), key=lambda item: item[1], reverse=True)[:10]
|
|
||||||
|
|
||||||
await self.message(c, '[\x036coin\x0f] richest users: '+', '.join(
|
async def richest(self, c, n, m):
|
||||||
[
|
richest = sorted((await bal(self)).items(), key=lambda item: item[1], reverse=True)[
|
||||||
i[0][:1]+"\u200c"+i[0][1:]+": "+str(round(i[1],2))
|
:10
|
||||||
for i in richest]
|
]
|
||||||
))
|
|
||||||
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036coin\x0f] richest users: "
|
||||||
|
+ ", ".join(
|
||||||
|
[
|
||||||
|
i[0][:1] + "\u200c" + i[0][1:] + ": " + str(round(i[1], 2))
|
||||||
|
for i in richest
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.ledger = shared.db['ledger']
|
self.ledger = shared.db["ledger"]
|
||||||
self.initfund = 1
|
self.initfund = 1
|
||||||
|
|
||||||
shared.commands['tipcoins'] = send
|
shared.commands["tipcoins"] = send
|
||||||
shared.commands['sendcoins'] = send
|
shared.commands["sendcoins"] = send
|
||||||
shared.commands['balance'] = balance
|
shared.commands["balance"] = balance
|
||||||
shared.commands['richest'] = richest
|
shared.commands["richest"] = richest
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
self.help['sendcoins'] = ['sendcoins <recipient> <amount> [message] - send someone coins. note (more)','this does NOT verify transactions went through!! check your balance after']
|
self.help["sendcoins"] = [
|
||||||
self.help['balance'] = ['balance [person] - check someone\'s balance','coins owo']
|
"sendcoins <recipient> <amount> [message] - send someone coins. note (more)",
|
||||||
self.help['richest'] = ['richest - who has the most coins','coins owo']
|
"this does NOT verify transactions went through!! check your balance after",
|
||||||
|
]
|
||||||
|
self.help["balance"] = ["balance [person] - check someone's balance", "coins owo"]
|
||||||
|
self.help["richest"] = ["richest - who has the most coins", "coins owo"]
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
from irctokens import build, Line
|
from irctokens import build, Line
|
||||||
import bot
|
import bot
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.admins = ['xfnw','lickthecheese']
|
self.admins = ["xfnw", "lickthecheese"]
|
||||||
|
|
||||||
|
|
|
@ -3,46 +3,50 @@ import random
|
||||||
from bot import *
|
from bot import *
|
||||||
|
|
||||||
|
|
||||||
async def coffeeup(self,c,n,m):
|
async def coffeeup(self, c, n, m):
|
||||||
m = m.lower()
|
m = m.lower()
|
||||||
c = c.lower()
|
c = c.lower()
|
||||||
if c in ['#coffee','#tea','#water','#caps','#sodawater']:
|
if c in ["#coffee", "#tea", "#water", "#caps", "#sodawater"]:
|
||||||
if (
|
if (
|
||||||
(c[1:]+"!" in m and c+'!' not in m)
|
(c[1:] + "!" in m and c + "!" not in m)
|
||||||
or c=='#coffee' and ('latte!' in m or 'espresso!' in m or 'cappucino!' in m)
|
or c == "#coffee"
|
||||||
or c=='#tea' and ('chai!' in m or 'kombucha!' in m)
|
and ("latte!" in m or "espresso!" in m or "cappucino!" in m)
|
||||||
):
|
or c == "#tea"
|
||||||
|
and ("chai!" in m or "kombucha!" in m)
|
||||||
|
):
|
||||||
cc = self.coffee.find_one(name=c)
|
cc = self.coffee.find_one(name=c)
|
||||||
if cc:
|
if cc:
|
||||||
self.coffee.update(dict(name=c,value=cc['value']+1),['name'])
|
self.coffee.update(dict(name=c, value=cc["value"] + 1), ["name"])
|
||||||
else:
|
else:
|
||||||
self.coffee.insert(dict(name=c,value=1))
|
self.coffee.insert(dict(name=c, value=1))
|
||||||
if c=='#CAPS':
|
if c == "#CAPS":
|
||||||
await message(self, c, '・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()).upper())
|
await message(
|
||||||
|
self, c, "・゜゜・。。・゜゜c[~] {} UP!".format(c[1:].upper()).upper()
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await message(self, c, '・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()))
|
await message(self, c, "・゜゜・。。・゜゜c[~] {} UP!".format(c[1:].upper()))
|
||||||
elif "cupcount" in m:
|
elif "cupcount" in m:
|
||||||
await message(self, c, '{} delicious cups of {}{} served so far!'.format(
|
await message(
|
||||||
self.coffee.find_one(name=c)['value'], random.choice(self.coffeetypes), c[1:]
|
self,
|
||||||
))
|
c,
|
||||||
|
"{} delicious cups of {}{} served so far!".format(
|
||||||
|
self.coffee.find_one(name=c)["value"],
|
||||||
|
random.choice(self.coffeetypes),
|
||||||
|
c[1:],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
shared.rawm['coffeeup'] = coffeeup
|
shared.rawm["coffeeup"] = coffeeup
|
||||||
self.coffee = shared.db['coffee']
|
self.coffee = shared.db["coffee"]
|
||||||
|
|
||||||
self.coffeetypes = [
|
self.coffeetypes = [
|
||||||
"kum\u200cquat's aeropressed ",
|
"kum\u200cquat's aeropressed ",
|
||||||
"hot ",
|
"hot ",
|
||||||
"OSHA-compliant ",
|
"OSHA-compliant ",
|
||||||
"cmc\u200ccabe's nom nom nom yummy ",
|
"cmc\u200ccabe's nom nom nom yummy ",
|
||||||
"healthy ",
|
"healthy ",
|
||||||
]
|
]
|
||||||
for i in range(len(self.coffeetypes)):
|
for i in range(len(self.coffeetypes)):
|
||||||
self.coffeetypes.append('')
|
self.coffeetypes.append("")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,31 @@
|
||||||
from bot import *
|
from bot import *
|
||||||
import json, requests
|
import json, requests
|
||||||
|
|
||||||
@command('lookup')
|
|
||||||
async def lookup(self,c,n,m):
|
@command("lookup")
|
||||||
if len(m) < 1:
|
async def lookup(self, c, n, m):
|
||||||
await self.message(c, '[\x036ham\x0f] you need the callsign lol')
|
if len(m) < 1:
|
||||||
return
|
await self.message(c, "[\x036ham\x0f] you need the callsign lol")
|
||||||
res = requests.get('https://callook.info/{}/json'.format(m))
|
return
|
||||||
if res.status_code :
|
res = requests.get("https://callook.info/{}/json".format(m))
|
||||||
js = res.json()
|
if res.status_code:
|
||||||
if js['status'] == 'VALID':
|
js = res.json()
|
||||||
await self.message(c, '[\x036ham\x0f] {}, name: {} grid: {}, expires: {}'.format(js['current']['operClass'], js['name'], js['location']['gridsquare'], js['otherInfo']['expiryDate']))
|
if js["status"] == "VALID":
|
||||||
return
|
await self.message(
|
||||||
await self.message(c, '[\x036ham\x0f] invalid callsign')
|
c,
|
||||||
else:
|
"[\x036ham\x0f] {}, name: {} grid: {}, expires: {}".format(
|
||||||
await self.message(c, '[\x036ham\x0f] something went wrong...')
|
js["current"]["operClass"],
|
||||||
|
js["name"],
|
||||||
|
js["location"]["gridsquare"],
|
||||||
|
js["otherInfo"]["expiryDate"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
await self.message(c, "[\x036ham\x0f] invalid callsign")
|
||||||
|
else:
|
||||||
|
await self.message(c, "[\x036ham\x0f] something went wrong...")
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
pass
|
pass
|
||||||
#self.help['lookup'] = ['lookup <callsign> - lookup a ham callsign','ROBERT']
|
# self.help['lookup'] = ['lookup <callsign> - lookup a ham callsign','ROBERT']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
|
||||||
from bot import *
|
from bot import *
|
||||||
|
|
||||||
@listener('INVITE')
|
|
||||||
async def on_invite(self,line):
|
@listener("INVITE")
|
||||||
self.send(build("JOIN",[line.params[1]]))
|
async def on_invite(self, line):
|
||||||
|
self.send(build("JOIN", [line.params[1]]))
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
pass
|
pass
|
||||||
|
|
159
modules/keep.py
159
modules/keep.py
|
@ -1,89 +1,96 @@
|
||||||
from bot import *
|
from bot import *
|
||||||
import random
|
import random
|
||||||
|
|
||||||
async def getkeep(self,c,n,m):
|
|
||||||
m = m.strip()
|
async def getkeep(self, c, n, m):
|
||||||
if len(m) < 1:
|
m = m.strip()
|
||||||
keep = random.choice([i['keep'] for i in self.keepdb.find()])
|
if len(m) < 1:
|
||||||
else:
|
keep = random.choice([i["keep"] for i in self.keepdb.find()])
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
keep = random.choice(
|
||||||
|
[i["keep"] for i in self.keepdb.find(keep={"like": "%{}%".format(m)})]
|
||||||
|
)
|
||||||
|
except IndexError:
|
||||||
|
await self.message(c, "[\x036keep\x0f] No keeps found.")
|
||||||
|
return
|
||||||
|
await self.message(c, "[\x036keep\x0f] {}".format(keep))
|
||||||
|
|
||||||
|
|
||||||
|
async def grabkeep(self, c, n, m):
|
||||||
|
if len(m) < 1:
|
||||||
|
m = "1"
|
||||||
try:
|
try:
|
||||||
keep = random.choice([i['keep'] for i in self.keepdb.find(keep={'like':"%{}%".format(m)})])
|
back = int(m) + 0
|
||||||
except IndexError:
|
except:
|
||||||
await self.message(c,'[\x036keep\x0f] No keeps found.')
|
m = m.strip().split(" ")
|
||||||
return
|
if c in self.owolog:
|
||||||
await self.message(c,'[\x036keep\x0f] {}'.format(keep))
|
backlog = [i for i in self.owolog[c] if m[0] == i[0]]
|
||||||
|
if len(backlog) < 1:
|
||||||
|
await self.message(c, "[\x036keep\x0f] nothing found to keep")
|
||||||
async def grabkeep(self,c,n,m):
|
return
|
||||||
if len(m) < 1:
|
try:
|
||||||
m="1"
|
ms = backlog[0 - int(m[1])]
|
||||||
try:
|
except:
|
||||||
back = int(m)+0
|
ms = backlog[-1]
|
||||||
except:
|
m = "<{}> {}".format(ms[0], ms[1])
|
||||||
m = m.strip().split(' ')
|
self.keepdb.insert(dict(channel=c, nick=n, keep=m))
|
||||||
if c in self.owolog:
|
await self.message(c, "[\x036keep\x0f] keep added!")
|
||||||
backlog = [i for i in self.owolog[c] if m[0] == i[0]]
|
|
||||||
if len(backlog) < 1:
|
|
||||||
await self.message(c,'[\x036keep\x0f] nothing found to keep')
|
|
||||||
return
|
return
|
||||||
try:
|
if c in self.owolog and len(self.owolog[c]) >= back:
|
||||||
ms = backlog[0-int(m[1])]
|
ms = self.owolog[c][0 - back]
|
||||||
except:
|
m = "<{}> {}".format(ms[0], ms[1])
|
||||||
ms = backlog[-1]
|
|
||||||
m = "<{}> {}".format(ms[0],ms[1])
|
|
||||||
self.keepdb.insert(dict(channel=c,nick=n,keep=m))
|
|
||||||
await self.message(c,'[\x036keep\x0f] keep added!')
|
|
||||||
return
|
|
||||||
if c in self.owolog and len(self.owolog[c]) >= back:
|
|
||||||
ms = self.owolog[c][0-back]
|
|
||||||
m = "<{}> {}".format(ms[0],ms[1])
|
|
||||||
else:
|
|
||||||
await self.message(c,'[\x036keep\x0f] My backlog does not go back that far ;_;]')
|
|
||||||
return
|
|
||||||
self.keepdb.insert(dict(channel=c,nick=n,keep=m))
|
|
||||||
await self.message(c,'[\x036keep\x0f] keep added!')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def addkeep(self,c,n,m):
|
|
||||||
self.keepdb.insert(dict(channel=c,nick=n,keep=m))
|
|
||||||
await self.message(c,'[\x036keep\x0f] keep added!')
|
|
||||||
|
|
||||||
async def rmkeep(self,c,n,m):
|
|
||||||
if n in self.channels[self.rmkeepchan].users and 'o' in self.channels[self.rmkeepchan].users[n].modes:
|
|
||||||
co = m.strip().split(' ')
|
|
||||||
if len(co) < 2:
|
|
||||||
await self.message(c,'[\x036keep\x0f] wrong syntax')
|
|
||||||
return
|
|
||||||
crit = co.pop(0)
|
|
||||||
filt = ' '.join(co)
|
|
||||||
if crit == 'nick' or crit == 'n':
|
|
||||||
ou = self.keepdb.delete(nick=filt)
|
|
||||||
elif crit == 'quote' or crit == 'q':
|
|
||||||
ou = self.keepdb.delete(keep={'like':filt})
|
|
||||||
else:
|
else:
|
||||||
await self.message(c,'[\x036keep\x0f] invalid criterea')
|
await self.message(
|
||||||
if ou:
|
c, "[\x036keep\x0f] My backlog does not go back that far ;_;]"
|
||||||
await self.message(c, '[\x036keep\x0f] removed some keep(s)')
|
)
|
||||||
|
return
|
||||||
|
self.keepdb.insert(dict(channel=c, nick=n, keep=m))
|
||||||
|
await self.message(c, "[\x036keep\x0f] keep added!")
|
||||||
|
|
||||||
|
|
||||||
|
async def addkeep(self, c, n, m):
|
||||||
|
self.keepdb.insert(dict(channel=c, nick=n, keep=m))
|
||||||
|
await self.message(c, "[\x036keep\x0f] keep added!")
|
||||||
|
|
||||||
|
|
||||||
|
async def rmkeep(self, c, n, m):
|
||||||
|
if (
|
||||||
|
n in self.channels[self.rmkeepchan].users
|
||||||
|
and "o" in self.channels[self.rmkeepchan].users[n].modes
|
||||||
|
):
|
||||||
|
co = m.strip().split(" ")
|
||||||
|
if len(co) < 2:
|
||||||
|
await self.message(c, "[\x036keep\x0f] wrong syntax")
|
||||||
|
return
|
||||||
|
crit = co.pop(0)
|
||||||
|
filt = " ".join(co)
|
||||||
|
if crit == "nick" or crit == "n":
|
||||||
|
ou = self.keepdb.delete(nick=filt)
|
||||||
|
elif crit == "quote" or crit == "q":
|
||||||
|
ou = self.keepdb.delete(keep={"like": filt})
|
||||||
|
else:
|
||||||
|
await self.message(c, "[\x036keep\x0f] invalid criterea")
|
||||||
|
if ou:
|
||||||
|
await self.message(c, "[\x036keep\x0f] removed some keep(s)")
|
||||||
|
else:
|
||||||
|
await self.message(c, "[\x036keep\x0f] did not remove any")
|
||||||
else:
|
else:
|
||||||
await self.message(c, '[\x036keep\x0f] did not remove any')
|
await self.message(c, f"[\x036keep\x0f] you must have +o in {self.rmkeepchan}")
|
||||||
else:
|
|
||||||
await self.message(c,f'[\x036keep\x0f] you must have +o in {self.rmkeepchan}')
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.keepdb = shared.db['keep']
|
self.keepdb = shared.db["keep"]
|
||||||
|
|
||||||
shared.commands['keep'] = getkeep
|
shared.commands["keep"] = getkeep
|
||||||
#self.help['keep'] = ['keep - get keeps about keep','lets learn about keep!']
|
# self.help['keep'] = ['keep - get keeps about keep','lets learn about keep!']
|
||||||
|
|
||||||
shared.commands['addkeep'] = addkeep
|
|
||||||
#self.help['addkeep'] = ['addkeep <keep> - add a new keep (more)','if you find something offensive contact lickthecheese, he can remove it and/or tell you who added it so watch out!']
|
|
||||||
|
|
||||||
shared.commands['grabkeep'] = grabkeep
|
shared.commands["addkeep"] = addkeep
|
||||||
#self.help['grabkeep'] = ['grabkeep [back] - grab something to keep','tooootally did not steal this from bitbot']
|
# self.help['addkeep'] = ['addkeep <keep> - add a new keep (more)','if you find something offensive contact lickthecheese, he can remove it and/or tell you who added it so watch out!']
|
||||||
|
|
||||||
self.rmkeepchan = "#balun"
|
shared.commands["grabkeep"] = grabkeep
|
||||||
shared.commands['rmkeep'] = rmkeep
|
# self.help['grabkeep'] = ['grabkeep [back] - grab something to keep','tooootally did not steal this from bitbot']
|
||||||
#self.help['rmkeep'] = ['rmkeep <criteria> <pattern> - remove some keep(s). criteria types in (more)','types of criteria: n|nick q|quote eg "rmkeep nick spammer" to get rid of all keeps created by nick spammer']
|
|
||||||
|
|
||||||
|
self.rmkeepchan = "#balun"
|
||||||
|
shared.commands["rmkeep"] = rmkeep
|
||||||
|
# self.help['rmkeep'] = ['rmkeep <criteria> <pattern> - remove some keep(s). criteria types in (more)','types of criteria: n|nick q|quote eg "rmkeep nick spammer" to get rid of all keeps created by nick spammer']
|
||||||
|
|
|
@ -1,38 +1,43 @@
|
||||||
from bot import *
|
from bot import *
|
||||||
import random
|
import random
|
||||||
|
|
||||||
async def owologger(self,c,n,m):
|
|
||||||
print("<{} {}> {}".format(c,n,m))
|
|
||||||
if m[:len(shared.prefix)] == shared.prefix:
|
|
||||||
return
|
|
||||||
if c not in self.owolog:
|
|
||||||
self.owolog[c] = []
|
|
||||||
|
|
||||||
self.owolog[c].append([n,m])
|
async def owologger(self, c, n, m):
|
||||||
if len(self.owolog[c]) > 333:
|
print("<{} {}> {}".format(c, n, m))
|
||||||
del self.owolog[c][:-300]
|
if m[: len(shared.prefix)] == shared.prefix:
|
||||||
|
return
|
||||||
|
if c not in self.owolog:
|
||||||
|
self.owolog[c] = []
|
||||||
|
|
||||||
|
self.owolog[c].append([n, m])
|
||||||
|
if len(self.owolog[c]) > 333:
|
||||||
|
del self.owolog[c][:-300]
|
||||||
|
|
||||||
|
|
||||||
|
async def owoify(self, c, n, m):
|
||||||
|
if len(m) < 1:
|
||||||
|
m = "1"
|
||||||
|
try:
|
||||||
|
back = int(m) + 0
|
||||||
|
except:
|
||||||
|
back = 1
|
||||||
|
await self.message(c, await owotext(self, back, c))
|
||||||
|
|
||||||
async def owoify(self,c,n,m):
|
|
||||||
if len(m) < 1:
|
|
||||||
m = "1"
|
|
||||||
try:
|
|
||||||
back = int(m)+0
|
|
||||||
except:
|
|
||||||
back = 1
|
|
||||||
await self.message(c, await owotext(self, back, c))
|
|
||||||
|
|
||||||
async def owotext(self, back, chan):
|
async def owotext(self, back, chan):
|
||||||
if chan in self.owolog and len(self.owolog[chan]) >= back:
|
if chan in self.owolog and len(self.owolog[chan]) >= back:
|
||||||
ms = self.owolog[chan][0-back]
|
ms = self.owolog[chan][0 - back]
|
||||||
ms[1] = ms[1].replace('r','w').replace('l','w').replace('uck','uwk')
|
ms[1] = ms[1].replace("r", "w").replace("l", "w").replace("uck", "uwk")
|
||||||
return '<{}> {} {}'.format(ms[0],ms[1],random.choice(['owo','uwu','^w^','Owo?','OwO', 'oWo', 'UwU', 'uWu']))
|
return "<{}> {} {}".format(
|
||||||
return 'My backlog does not go back that far :('
|
ms[0],
|
||||||
|
ms[1],
|
||||||
|
random.choice(["owo", "uwu", "^w^", "Owo?", "OwO", "oWo", "UwU", "uWu"]),
|
||||||
|
)
|
||||||
|
return "My backlog does not go back that far :("
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.owolog = {}
|
self.owolog = {}
|
||||||
shared.rawm['owolog'] = owologger
|
shared.rawm["owolog"] = owologger
|
||||||
shared.commands['owo'] = owoify
|
shared.commands["owo"] = owoify
|
||||||
#self.help['owo'] = ['owo [num] - owoify the text', 'owo owo uwu']
|
# self.help['owo'] = ['owo [num] - owoify the text', 'owo owo uwu']
|
||||||
|
|
||||||
|
|
166
modules/rpn.py
166
modules/rpn.py
|
@ -1,93 +1,107 @@
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from bot import *
|
from bot import *
|
||||||
|
|
||||||
|
|
||||||
def isfloat(value):
|
def isfloat(value):
|
||||||
try:
|
try:
|
||||||
float(value)
|
float(value)
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def rpninp(self, chan, nick, msg):
|
async def rpninp(self, chan, nick, msg):
|
||||||
if chan not in self.rpnhist:
|
if chan not in self.rpnhist:
|
||||||
self.rpnhist[chan] = [0]
|
self.rpnhist[chan] = [0]
|
||||||
try:
|
try:
|
||||||
msg = msg.replace('+',' + ')
|
msg = msg.replace("+", " + ")
|
||||||
msg = msg.replace('a',' a ')
|
msg = msg.replace("a", " a ")
|
||||||
#msg = msg.replace('-',' - ')
|
# msg = msg.replace('-',' - ')
|
||||||
msg = msg.replace('s',' s ')
|
msg = msg.replace("s", " s ")
|
||||||
msg = msg.replace('\\',' \\ ')
|
msg = msg.replace("\\", " \\ ")
|
||||||
msg = msg.replace('*',' * ')
|
msg = msg.replace("*", " * ")
|
||||||
msg = msg.replace('x',' x ')
|
msg = msg.replace("x", " x ")
|
||||||
msg = msg.replace('m',' m ')
|
msg = msg.replace("m", " m ")
|
||||||
msg = msg.replace('/',' / ')
|
msg = msg.replace("/", " / ")
|
||||||
msg = msg.replace('d',' d ')
|
msg = msg.replace("d", " d ")
|
||||||
msg = msg.replace('^',' ^ ')
|
msg = msg.replace("^", " ^ ")
|
||||||
msg = msg.replace('e',' e ')
|
msg = msg.replace("e", " e ")
|
||||||
for m in msg.split():
|
for m in msg.split():
|
||||||
self.rpnhist[chan].append(0)
|
self.rpnhist[chan].append(0)
|
||||||
del self.rpnhist[chan][15:]
|
del self.rpnhist[chan][15:]
|
||||||
if isfloat(m):
|
if isfloat(m):
|
||||||
self.rpnhist[chan].insert(0, float(m))
|
self.rpnhist[chan].insert(0, float(m))
|
||||||
continue
|
continue
|
||||||
elif m == '+' or m == 'a':
|
elif m == "+" or m == "a":
|
||||||
self.rpnhist[chan][0] = self.rpnhist[chan][0]+self.rpnhist[chan].pop(1)
|
self.rpnhist[chan][0] = self.rpnhist[chan][0] + self.rpnhist[chan].pop(
|
||||||
elif m == '-' or m == 's':
|
1
|
||||||
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)-self.rpnhist[chan][0]
|
)
|
||||||
elif m == '\\':
|
elif m == "-" or m == "s":
|
||||||
self.rpnhist[chan].insert(0,self.rpnhist[chan][0])
|
self.rpnhist[chan][0] = (
|
||||||
elif m == '*' or m == 'x' or m == 'm':
|
self.rpnhist[chan].pop(1) - self.rpnhist[chan][0]
|
||||||
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)*self.rpnhist[chan][0]
|
)
|
||||||
elif m == '/' or m == 'd':
|
elif m == "\\":
|
||||||
try:
|
self.rpnhist[chan].insert(0, self.rpnhist[chan][0])
|
||||||
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)/self.rpnhist[chan][0]
|
elif m == "*" or m == "x" or m == "m":
|
||||||
except ZeroDivisionError:
|
self.rpnhist[chan][0] = (
|
||||||
self.rpnhist[chan][0] = float('NaN')
|
self.rpnhist[chan].pop(1) * self.rpnhist[chan][0]
|
||||||
elif m == '^' or m == 'e':
|
)
|
||||||
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)**self.rpnhist[chan][0]
|
elif m == "/" or m == "d":
|
||||||
elif msg == 'p':
|
try:
|
||||||
pass # just dont do anything lol
|
self.rpnhist[chan][0] = (
|
||||||
elif msg == 'r':
|
self.rpnhist[chan].pop(1) / self.rpnhist[chan][0]
|
||||||
if chan in self.rpnprint:
|
)
|
||||||
await self.message(chan, '[\x036rpn\x0f] {}'.format(str(self.rpnhist[chan])))
|
except ZeroDivisionError:
|
||||||
return
|
self.rpnhist[chan][0] = float("NaN")
|
||||||
else:
|
elif m == "^" or m == "e":
|
||||||
return
|
self.rpnhist[chan][0] = (
|
||||||
except OverflowError:
|
self.rpnhist[chan].pop(1) ** self.rpnhist[chan][0]
|
||||||
|
)
|
||||||
|
elif msg == "p":
|
||||||
|
pass # just dont do anything lol
|
||||||
|
elif msg == "r":
|
||||||
|
if chan in self.rpnprint:
|
||||||
|
await self.message(
|
||||||
|
chan, "[\x036rpn\x0f] {}".format(str(self.rpnhist[chan]))
|
||||||
|
)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
except OverflowError:
|
||||||
|
if chan in self.rpnprint:
|
||||||
|
await self.message(chan, "[\x036rpn\x0f] no u ur numbers are too phat")
|
||||||
|
return
|
||||||
if chan in self.rpnprint:
|
if chan in self.rpnprint:
|
||||||
await self.message(chan, '[\x036rpn\x0f] no u ur numbers are too phat')
|
await self.message(chan, "[\x036rpn\x0f] " + str(self.rpnhist[chan][0]))
|
||||||
return
|
|
||||||
if chan in self.rpnprint:
|
|
||||||
await self.message(chan, '[\x036rpn\x0f] '+str(self.rpnhist[chan][0]))
|
|
||||||
|
|
||||||
|
|
||||||
async def rpntinp(self, chan, nick, msg):
|
async def rpntinp(self, chan, nick, msg):
|
||||||
if chan in self.rpnprint:
|
if chan in self.rpnprint:
|
||||||
|
|
||||||
await rpninp(self, chan, nick, msg)
|
await rpninp(self, chan, nick, msg)
|
||||||
else:
|
else:
|
||||||
self.rpnprint.append(chan)
|
self.rpnprint.append(chan)
|
||||||
await rpninp(self, chan, nick, msg)
|
await rpninp(self, chan, nick, msg)
|
||||||
self.rpnprint.remove(chan)
|
self.rpnprint.remove(chan)
|
||||||
|
|
||||||
|
|
||||||
async def rpntoggle(self, chan, nick, msg):
|
async def rpntoggle(self, chan, nick, msg):
|
||||||
if chan in self.rpnprint:
|
if chan in self.rpnprint:
|
||||||
self.rpnprint.remove(chan)
|
self.rpnprint.remove(chan)
|
||||||
await self.message(chan, '[\x036rpn\x0f] rpn outputting has been disabled')
|
await self.message(chan, "[\x036rpn\x0f] rpn outputting has been disabled")
|
||||||
else:
|
else:
|
||||||
self.rpnprint.append(chan)
|
self.rpnprint.append(chan)
|
||||||
await self.message(chan, '[\x036rpn\x0f] rpn outputting has been enabled')
|
await self.message(chan, "[\x036rpn\x0f] rpn outputting has been enabled")
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
#self.help['rpn'] = ['rpn <inp> - simple reverse polish notation calculator (more)', 'it has an alias of . so you can just do {}. <inp>, and if enabled it will also parse floats and functions as input. there are 4 functions, add (+|a), subtract (-|s), multiply (*|x|m), and devide (/|d), and p to print register 0'.format(self.prefix)]
|
# self.help['rpn'] = ['rpn <inp> - simple reverse polish notation calculator (more)', 'it has an alias of . so you can just do {}. <inp>, and if enabled it will also parse floats and functions as input. there are 4 functions, add (+|a), subtract (-|s), multiply (*|x|m), and devide (/|d), and p to print register 0'.format(self.prefix)]
|
||||||
shared.commands['rpn'] = rpntinp
|
shared.commands["rpn"] = rpntinp
|
||||||
shared.commands['.'] = rpntinp
|
shared.commands["."] = rpntinp
|
||||||
shared.rawm['rpn'] = rpninp
|
shared.rawm["rpn"] = rpninp
|
||||||
shared.commands['rt'] = rpntoggle
|
shared.commands["rt"] = rpntoggle
|
||||||
#self.help['rt'] = ['rt - toggle the output of rpn calculatons into the channel', 'rpn is cool']
|
# self.help['rt'] = ['rt - toggle the output of rpn calculatons into the channel', 'rpn is cool']
|
||||||
|
|
||||||
self.rpnhist = {}
|
self.rpnhist = {}
|
||||||
|
|
||||||
self.rpnprint = []
|
self.rpnprint = []
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import bot
|
import bot
|
||||||
|
|
||||||
|
|
||||||
@bot.command('test')
|
@bot.command("test")
|
||||||
@bot.is_admin
|
@bot.is_admin
|
||||||
async def testy(self,channel,nick,msg):
|
async def testy(self, channel, nick, msg):
|
||||||
await bot.message(self,channel,'hi there')
|
await bot.message(self, channel, "hi there")
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
|
|
||||||
await self.send_raw("join #bots")
|
await self.send_raw("join #bots")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
|
async def action(self, c, n, m):
|
||||||
async def action(self,c,n,m):
|
await self.message(c, "\x01ACTION {}\x01".format(m[:400]))
|
||||||
await self.message(c,'\x01ACTION {}\x01'.format(m[:400]))
|
|
||||||
|
|
||||||
|
|
||||||
async def echo(self,c,n,m):
|
async def echo(self, c, n, m):
|
||||||
await self.message(c,'[\x036channels\x0f] {}'.format(m[:400]))
|
await self.message(c, "[\x036channels\x0f] {}".format(m[:400]))
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.chansjoin = ['#bots']
|
self.chansjoin = ["#bots"]
|
||||||
|
|
||||||
self.cmd['echo']=echo
|
|
||||||
self.cmd['action']=action
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.cmd["echo"] = echo
|
||||||
|
self.cmd["action"] = action
|
||||||
|
|
|
@ -1,52 +1,62 @@
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
async def getfact(self,c,n,m):
|
|
||||||
if len(m) < 1:
|
|
||||||
fact = random.choice([i['fact'] for i in self.est.find()])
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
fact = random.choice([i['fact'] for i in self.est.find(fact={'like':"%{}%".format(m)})])
|
|
||||||
except IndexError:
|
|
||||||
await self.message(c,'[\x036estonia\x0f] No facts found.')
|
|
||||||
return
|
|
||||||
await self.message(c,'[\x036estonia\x0f] fact: {}'.format(fact))
|
|
||||||
|
|
||||||
async def addfact(self,c,n,m):
|
async def getfact(self, c, n, m):
|
||||||
self.est.insert(dict(channel=c,nick=n,fact=m))
|
if len(m) < 1:
|
||||||
await self.message(c,'[\x036estonia\x0f] fact added!')
|
fact = random.choice([i["fact"] for i in self.est.find()])
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
fact = random.choice(
|
||||||
|
[i["fact"] for i in self.est.find(fact={"like": "%{}%".format(m)})]
|
||||||
|
)
|
||||||
|
except IndexError:
|
||||||
|
await self.message(c, "[\x036estonia\x0f] No facts found.")
|
||||||
|
return
|
||||||
|
await self.message(c, "[\x036estonia\x0f] fact: {}".format(fact))
|
||||||
|
|
||||||
async def rmfact(self,c,n,m):
|
|
||||||
if n in self.channels[self.rmfactchan]['modes']['o']:
|
async def addfact(self, c, n, m):
|
||||||
co = m.strip().split(' ')
|
self.est.insert(dict(channel=c, nick=n, fact=m))
|
||||||
if len(co) < 2:
|
await self.message(c, "[\x036estonia\x0f] fact added!")
|
||||||
await self.message(c,'[\x036estonia\x0f] wrong syntax')
|
|
||||||
return
|
|
||||||
crit = co.pop(0)
|
async def rmfact(self, c, n, m):
|
||||||
filt = ' '.join(co)
|
if n in self.channels[self.rmfactchan]["modes"]["o"]:
|
||||||
if crit == 'nick' or crit == 'n':
|
co = m.strip().split(" ")
|
||||||
ou = self.est.delete(nick=filt)
|
if len(co) < 2:
|
||||||
elif crit == 'fact' or crit == 'f':
|
await self.message(c, "[\x036estonia\x0f] wrong syntax")
|
||||||
ou = self.est.delete(fact={'like':filt})
|
return
|
||||||
|
crit = co.pop(0)
|
||||||
|
filt = " ".join(co)
|
||||||
|
if crit == "nick" or crit == "n":
|
||||||
|
ou = self.est.delete(nick=filt)
|
||||||
|
elif crit == "fact" or crit == "f":
|
||||||
|
ou = self.est.delete(fact={"like": filt})
|
||||||
|
else:
|
||||||
|
await self.message(c, "[\x036estonia\x0f] invalid criterea")
|
||||||
|
if ou:
|
||||||
|
await self.message(c, "[\x036estonia\x0f] removed some fact(s)")
|
||||||
|
else:
|
||||||
|
await self.message(c, "[\x036estonia\x0f] did not remove any")
|
||||||
else:
|
else:
|
||||||
await self.message(c,'[\x036estonia\x0f] invalid criterea')
|
await self.message(c, "[\x036estonia\x0f] you must have +o in #estonia")
|
||||||
if ou:
|
|
||||||
await self.message(c, '[\x036estonia\x0f] removed some fact(s)')
|
|
||||||
else:
|
|
||||||
await self.message(c, '[\x036estonia\x0f] did not remove any')
|
|
||||||
else:
|
|
||||||
await self.message(c,'[\x036estonia\x0f] you must have +o in #estonia')
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.est = self.db['estonia']
|
self.est = self.db["estonia"]
|
||||||
|
|
||||||
self.cmd['fact'] = getfact
|
self.cmd["fact"] = getfact
|
||||||
self.help['fact'] = ['fact - get facts about estonia','lets learn about estonia!']
|
self.help["fact"] = ["fact - get facts about estonia", "lets learn about estonia!"]
|
||||||
|
|
||||||
self.cmd['addfact'] = addfact
|
|
||||||
self.help['addfact'] = ['addfact <fact> - add a new fact (more)','if you find something offensive contact lickthecheese, he can remove it and/or tell you who added it so watch out!']
|
|
||||||
|
|
||||||
self.rmfactchan = "#estonia"
|
self.cmd["addfact"] = addfact
|
||||||
self.cmd['rmfact'] = rmfact
|
self.help["addfact"] = [
|
||||||
self.help['rmfact'] = ['rmfact <criteria> <pattern> - remove some fact(s). criteria types in (more)','types of criteria: n|nick f|fact eg "rmfact nick spammer" to get rid of all facts created by nick spammer']
|
"addfact <fact> - add a new fact (more)",
|
||||||
|
"if you find something offensive contact lickthecheese, he can remove it and/or tell you who added it so watch out!",
|
||||||
|
]
|
||||||
|
|
||||||
|
self.rmfactchan = "#estonia"
|
||||||
|
self.cmd["rmfact"] = rmfact
|
||||||
|
self.help["rmfact"] = [
|
||||||
|
"rmfact <criteria> <pattern> - remove some fact(s). criteria types in (more)",
|
||||||
|
'types of criteria: n|nick f|fact eg "rmfact nick spammer" to get rid of all facts created by nick spammer',
|
||||||
|
]
|
||||||
|
|
|
@ -1,35 +1,44 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def helpParse(self, c, n, m):
|
async def helpParse(self, c, n, m):
|
||||||
if m in self.help:
|
if m in self.help:
|
||||||
self.more[c] = self.help[m][1]
|
self.more[c] = self.help[m][1]
|
||||||
await self.message(c, '[\x036help\x0f] '+self.help[m][0])
|
await self.message(c, "[\x036help\x0f] " + self.help[m][0])
|
||||||
else:
|
else:
|
||||||
await self.message(c, '[\x036help\x0f] my nice commands are {}'.format(', '.join([i for i in self.help if not ' ' in i])))
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036help\x0f] my nice commands are {}".format(
|
||||||
|
", ".join([i for i in self.help if not " " in i])
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def more(self, c, n, m):
|
async def more(self, c, n, m):
|
||||||
if c in self.more:
|
if c in self.more:
|
||||||
moretext = self.more.pop(c)
|
moretext = self.more.pop(c)
|
||||||
if len(moretext) > 300:
|
if len(moretext) > 300:
|
||||||
self.more[c]=moretext[250:]
|
self.more[c] = moretext[250:]
|
||||||
moretext = moretext[:250]+' (more)'
|
moretext = moretext[:250] + " (more)"
|
||||||
|
|
||||||
await self.message(c, '[\x036help\x0f] '+moretext)
|
await self.message(c, "[\x036help\x0f] " + moretext)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
await self.message(c, '[\x036help\x0f] there is no more more text lmao stop')
|
await self.message(c, "[\x036help\x0f] there is no more more text lmao stop")
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.cmd['help'] = helpParse
|
self.cmd["help"] = helpParse
|
||||||
self.cmd['more'] = more
|
self.cmd["more"] = more
|
||||||
|
|
||||||
self.help['help'] = ['help command - list commands or show info about one', 'i hope this was helpful']
|
self.help["help"] = [
|
||||||
self.help['help command'] = ['help <command> - show more info about a command (more)', 'there is even a more, for a even more in depth look!']
|
"help command - list commands or show info about one",
|
||||||
self.help['more'] = ['more - see more stuff when there is (more)', 'good job you did it lol']
|
"i hope this was helpful",
|
||||||
|
]
|
||||||
|
self.help["help command"] = [
|
||||||
self.more={}
|
"help <command> - show more info about a command (more)",
|
||||||
|
"there is even a more, for a even more in depth look!",
|
||||||
|
]
|
||||||
|
self.help["more"] = [
|
||||||
|
"more - see more stuff when there is (more)",
|
||||||
|
"good job you did it lol",
|
||||||
|
]
|
||||||
|
|
||||||
|
self.more = {}
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
|
async def listMods(self, c, n, m):
|
||||||
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036modulemanager\x0f] currently loaded mods: {}".format(
|
||||||
|
list(self.modules.keys())
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def listMods(self,c,n,m):
|
async def source(self, c, n, m):
|
||||||
await self.message(c,'[\x036modulemanager\x0f] currently loaded mods: {}'.format(list(self.modules.keys())))
|
if m == self.nickname + ": source":
|
||||||
|
await self.message(
|
||||||
async def source(self,c,n,m):
|
c, "[\x036modulemanager\x0f] My source is at https://xfnw.ttm.sh/git/oirc/"
|
||||||
if m == self.nickname+': source':
|
)
|
||||||
await self.message(c,'[\x036modulemanager\x0f] My source is at https://xfnw.ttm.sh/git/oirc/')
|
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.help['modules'] = ['modules - list the modules',':o']
|
self.help["modules"] = ["modules - list the modules", ":o"]
|
||||||
self.cmd['modules'] = listMods
|
self.cmd["modules"] = listMods
|
||||||
self.rawm['source'] = source
|
self.rawm["source"] = source
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,42 @@
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
async def plogger(self,c,n,m):
|
|
||||||
if c not in self.plog:
|
|
||||||
self.plog[c] = []
|
|
||||||
|
|
||||||
self.plog[c].append([n,m])
|
async def plogger(self, c, n, m):
|
||||||
if len(self.plog[c]) > 50:
|
if c not in self.plog:
|
||||||
del self.plog[c][:-50]
|
self.plog[c] = []
|
||||||
|
|
||||||
|
self.plog[c].append([n, m])
|
||||||
|
if len(self.plog[c]) > 50:
|
||||||
|
del self.plog[c][:-50]
|
||||||
|
|
||||||
if c in self.channels and 'o' in self.channels[c]['modes'] and self.nickname in self.channels[c]['modes']['o'] and ('v' not in self.channels[c]['modes'] or n not in self.channels[c]['modes']['v']):
|
if (
|
||||||
# fun time
|
c in self.channels
|
||||||
umc = len([i for i in self.plog[c][-10:] if i[0]==n])
|
and "o" in self.channels[c]["modes"]
|
||||||
#await self.message(c,str(umc))
|
and self.nickname in self.channels[c]["modes"]["o"]
|
||||||
if umc > 6:
|
and (
|
||||||
if n in self.wlevel:
|
"v" not in self.channels[c]["modes"]
|
||||||
self.wlevel[n] += 1
|
or n not in self.channels[c]["modes"]["v"]
|
||||||
else:
|
)
|
||||||
self.wlevel[n] = 0
|
):
|
||||||
if self.wlevel[n] == 3:
|
# fun time
|
||||||
await self.set_mode(c,self.mutesyntax[0],self.mutesyntax[1].format(n+'!*@*'))
|
umc = len([i for i in self.plog[c][-10:] if i[0] == n])
|
||||||
if self.wlevel[n] > 10:
|
# await self.message(c,str(umc))
|
||||||
self.wlevel[n] = 0
|
if umc > 6:
|
||||||
await self.kick(c,n,'stop spamming thanks')
|
if n in self.wlevel:
|
||||||
|
self.wlevel[n] += 1
|
||||||
|
else:
|
||||||
|
self.wlevel[n] = 0
|
||||||
|
if self.wlevel[n] == 3:
|
||||||
|
await self.set_mode(
|
||||||
|
c, self.mutesyntax[0], self.mutesyntax[1].format(n + "!*@*")
|
||||||
|
)
|
||||||
|
if self.wlevel[n] > 10:
|
||||||
|
self.wlevel[n] = 0
|
||||||
|
await self.kick(c, n, "stop spamming thanks")
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.plog = {}
|
self.plog = {}
|
||||||
self.wlevel = {}
|
self.wlevel = {}
|
||||||
self.mutesyntax = ['+b','m:{}'] # ['+q','{}'] on freenode
|
self.mutesyntax = ["+b", "m:{}"] # ['+q','{}'] on freenode
|
||||||
self.rawm['preventionlog'] = plogger
|
self.rawm["preventionlog"] = plogger
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import requests, asyncio
|
import requests, asyncio
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,25 +14,23 @@ def timeDelta(dt):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
delta_time = dt - now
|
delta_time = dt - now
|
||||||
|
|
||||||
delta = delta_time.days * DAY + delta_time.seconds
|
delta = delta_time.days * DAY + delta_time.seconds
|
||||||
minutes = delta / MINUTE
|
minutes = delta / MINUTE
|
||||||
hours = delta / HOUR
|
hours = delta / HOUR
|
||||||
days = delta / DAY
|
days = delta / DAY
|
||||||
|
|
||||||
if delta < 0:
|
if delta < 0:
|
||||||
return "currently (should) be playing right now"
|
return "currently (should) be playing right now"
|
||||||
|
|
||||||
if delta < 1 * MINUTE:
|
if delta < 1 * MINUTE:
|
||||||
if delta == 1:
|
if delta == 1:
|
||||||
return "in one second"
|
return "in one second"
|
||||||
else:
|
else:
|
||||||
return str(delta) + " seconds to go"
|
return str(delta) + " seconds to go"
|
||||||
|
|
||||||
|
|
||||||
if delta < 2 * MINUTE:
|
if delta < 2 * MINUTE:
|
||||||
return "in a minute"
|
return "in a minute"
|
||||||
|
|
||||||
|
|
||||||
if delta < 45 * MINUTE:
|
if delta < 45 * MINUTE:
|
||||||
return str(int(minutes)) + " minutes to go"
|
return str(int(minutes)) + " minutes to go"
|
||||||
|
|
||||||
|
@ -49,7 +46,6 @@ def timeDelta(dt):
|
||||||
if delta < 30 * DAY:
|
if delta < 30 * DAY:
|
||||||
return str(int(days)) + " days to go"
|
return str(int(days)) + " days to go"
|
||||||
|
|
||||||
|
|
||||||
if delta < 12 * MONTH:
|
if delta < 12 * MONTH:
|
||||||
months = delta / MONTH
|
months = delta / MONTH
|
||||||
if months <= 1:
|
if months <= 1:
|
||||||
|
@ -57,14 +53,11 @@ def timeDelta(dt):
|
||||||
else:
|
else:
|
||||||
return str(int(months)) + " months to go"
|
return str(int(months)) + " months to go"
|
||||||
else:
|
else:
|
||||||
years = days / 365.0
|
years = days / 365.0
|
||||||
if years <= 1:
|
if years <= 1:
|
||||||
return "one year to go"
|
return "one year to go"
|
||||||
else:
|
else:
|
||||||
return str(int(years)) + " years to go"
|
return str(int(years)) + " years to go"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def formatSec(dt):
|
def formatSec(dt):
|
||||||
|
@ -74,20 +67,18 @@ def formatSec(dt):
|
||||||
hours = delta / HOUR
|
hours = delta / HOUR
|
||||||
days = delta / DAY
|
days = delta / DAY
|
||||||
|
|
||||||
if delta < 0:
|
if delta < 0:
|
||||||
return "??"
|
return "??"
|
||||||
|
|
||||||
if delta < 1 * MINUTE:
|
if delta < 1 * MINUTE:
|
||||||
if delta == 1:
|
if delta == 1:
|
||||||
return "one second"
|
return "one second"
|
||||||
else:
|
else:
|
||||||
return str(delta) + " seconds"
|
return str(delta) + " seconds"
|
||||||
|
|
||||||
|
|
||||||
if delta < 2 * MINUTE:
|
if delta < 2 * MINUTE:
|
||||||
return "a minute"
|
return "a minute"
|
||||||
|
|
||||||
|
|
||||||
if delta < 45 * MINUTE:
|
if delta < 45 * MINUTE:
|
||||||
return str(int(minutes)) + " minutes"
|
return str(int(minutes)) + " minutes"
|
||||||
|
|
||||||
|
@ -103,7 +94,6 @@ def formatSec(dt):
|
||||||
if delta < 30 * DAY:
|
if delta < 30 * DAY:
|
||||||
return str(int(days)) + " days"
|
return str(int(days)) + " days"
|
||||||
|
|
||||||
|
|
||||||
if delta < 12 * MONTH:
|
if delta < 12 * MONTH:
|
||||||
months = delta / MONTH
|
months = delta / MONTH
|
||||||
if months <= 1:
|
if months <= 1:
|
||||||
|
@ -111,63 +101,90 @@ def formatSec(dt):
|
||||||
else:
|
else:
|
||||||
return str(int(months)) + " months"
|
return str(int(months)) + " months"
|
||||||
else:
|
else:
|
||||||
years = days / 365.0
|
years = days / 365.0
|
||||||
if years <= 1:
|
if years <= 1:
|
||||||
return "one year"
|
return "one year"
|
||||||
else:
|
else:
|
||||||
return str(int(years)) + " years"
|
return str(int(years)) + " years"
|
||||||
|
|
||||||
|
|
||||||
async def upnext(self,c,n,m):
|
async def upnext(self, c, n, m):
|
||||||
if self.tildebot and c in self.channels and 'tildebot' in self.channels[c]['users']:
|
if self.tildebot and c in self.channels and "tildebot" in self.channels[c]["users"]:
|
||||||
return # only respond in #tr whilst tildebot is down
|
return # only respond in #tr whilst tildebot is down
|
||||||
res = requests.get('https://radio.tildeverse.org/api/station/1/schedule')
|
res = requests.get("https://radio.tildeverse.org/api/station/1/schedule")
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
js = res.json()
|
js = res.json()
|
||||||
if len(js) < 1:
|
if len(js) < 1:
|
||||||
await self.message(c,'[\x036radio\x0f] it appears that there is nothing on the schedule...')
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036radio\x0f] it appears that there is nothing on the schedule...",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
up = js[0]
|
up = js[0]
|
||||||
await self.message(c,'[\x036radio\x0f] Up next: {}, {}!'.format(up['name'],timeDelta(up['start_timestamp'])))
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036radio\x0f] Up next: {}, {}!".format(
|
||||||
|
up["name"], timeDelta(up["start_timestamp"])
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.message(c,'[\x036radio\x0f] something went wrong...')
|
await self.message(c, "[\x036radio\x0f] something went wrong...")
|
||||||
|
|
||||||
async def nowplaying(self,c,n,m):
|
|
||||||
if self.tildebot and c in self.channels and 'tildebot' in self.channels[c]['users']:
|
async def nowplaying(self, c, n, m):
|
||||||
return # only respond in #tr whilst tildebot is down
|
if self.tildebot and c in self.channels and "tildebot" in self.channels[c]["users"]:
|
||||||
|
return # only respond in #tr whilst tildebot is down
|
||||||
res = requests.get("https://radio.tildeverse.org/api/nowplaying/1")
|
res = requests.get("https://radio.tildeverse.org/api/nowplaying/1")
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
js = res.json()
|
js = res.json()
|
||||||
if "station" not in js:
|
if "station" not in js:
|
||||||
await self.message(c,'[\x036radio\x0f] something went wrong...')
|
await self.message(c, "[\x036radio\x0f] something went wrong...")
|
||||||
return
|
return
|
||||||
np = js['now_playing']
|
np = js["now_playing"]
|
||||||
#print(np)
|
# print(np)
|
||||||
if np['streamer'] == "":
|
if np["streamer"] == "":
|
||||||
await self.message(c,'[\x036radio\x0f] autodj has been playing {} for {} (next song in {})'.format(np['song']['text'],formatSec(np['elapsed']),formatSec(np['remaining']-1)))
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036radio\x0f] autodj has been playing {} for {} (next song in {})".format(
|
||||||
|
np["song"]["text"],
|
||||||
|
formatSec(np["elapsed"]),
|
||||||
|
formatSec(np["remaining"] - 1),
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.message(c,'[\x036radio\x0f] {} has been playing "{}" for {} (next song in {}) ({} listeners!)'.format(np['streamer'],np['song']['text'],formatSec(np['elapsed']),formatSec(np['remaining']-1),js['listeners']['current']))
|
await self.message(
|
||||||
|
c,
|
||||||
|
'[\x036radio\x0f] {} has been playing "{}" for {} (next song in {}) ({} listeners!)'.format(
|
||||||
|
np["streamer"],
|
||||||
|
np["song"]["text"],
|
||||||
|
formatSec(np["elapsed"]),
|
||||||
|
formatSec(np["remaining"] - 1),
|
||||||
|
js["listeners"]["current"],
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.message(c,'[\x036radio\x0f] something went wrong...')
|
await self.message(c, "[\x036radio\x0f] something went wrong...")
|
||||||
|
|
||||||
|
|
||||||
|
async def radioremind(self, c, n, m, scindex=0):
|
||||||
async def radioremind(self,c,n,m,scindex=0):
|
res = requests.get("https://radio.tildeverse.org/api/station/1/schedule")
|
||||||
res = requests.get('https://radio.tildeverse.org/api/station/1/schedule')
|
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
js = res.json()
|
js = res.json()
|
||||||
if len(js) < scindex+1:
|
if len(js) < scindex + 1:
|
||||||
await self.message(c,'[\x036radio\x0f] it appears that there is nothing on the schedule...')
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036radio\x0f] it appears that there is nothing on the schedule...",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
up = js[scindex]
|
up = js[scindex]
|
||||||
|
|
||||||
dt = datetime.datetime.fromtimestamp(up['start_timestamp'])
|
dt = datetime.datetime.fromtimestamp(up["start_timestamp"])
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
delta_time = (dt - now)
|
delta_time = dt - now
|
||||||
delta_time = (delta_time.days * DAY + delta_time.seconds) - 30
|
delta_time = (delta_time.days * DAY + delta_time.seconds) - 30
|
||||||
|
|
||||||
if delta_time < 1:
|
if delta_time < 1:
|
||||||
await radioremind(self,c,n,m,scindex=scindex+1)
|
await radioremind(self, c, n, m, scindex=scindex + 1)
|
||||||
return
|
return
|
||||||
if len(m.strip()) > 0:
|
if len(m.strip()) > 0:
|
||||||
toremind = m.strip()
|
toremind = m.strip()
|
||||||
|
@ -175,38 +192,56 @@ async def radioremind(self,c,n,m,scindex=0):
|
||||||
toremind = c
|
toremind = c
|
||||||
|
|
||||||
if toremind in self.rreminders:
|
if toremind in self.rreminders:
|
||||||
await self.message(c,'[\x036radio\x0f] There is already a reminder set for {}, you can also specify somewhere else to send the reminder'.format(toremind))
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036radio\x0f] There is already a reminder set for {}, you can also specify somewhere else to send the reminder".format(
|
||||||
|
toremind
|
||||||
|
),
|
||||||
|
)
|
||||||
return
|
return
|
||||||
await self.message(c,'[\x036radio\x0f] ok, il remind {} when its time for {}\'s show! (in {})'.format(toremind,up['name'],formatSec(delta_time)))
|
await self.message(
|
||||||
|
c,
|
||||||
task = asyncio.get_event_loop().create_task(remindTask(self, n, up, delta_time, toremind))
|
"[\x036radio\x0f] ok, il remind {} when its time for {}'s show! (in {})".format(
|
||||||
|
toremind, up["name"], formatSec(delta_time)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
task = asyncio.get_event_loop().create_task(
|
||||||
|
remindTask(self, n, up, delta_time, toremind)
|
||||||
|
)
|
||||||
self.rreminders[toremind] = task
|
self.rreminders[toremind] = task
|
||||||
try:
|
try:
|
||||||
await task
|
await task
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
print('Reminder for {} cancelled'.format(toremind))
|
print("Reminder for {} cancelled".format(toremind))
|
||||||
finally:
|
finally:
|
||||||
print('Reminder for {} finished'.format(toremind))
|
print("Reminder for {} finished".format(toremind))
|
||||||
self.rreminders.pop(toremind)
|
self.rreminders.pop(toremind)
|
||||||
else:
|
else:
|
||||||
await self.message(c,'[\x036radio\x0f] something went wrong...')
|
await self.message(c, "[\x036radio\x0f] something went wrong...")
|
||||||
|
|
||||||
async def remindTask(self, n, up, delta_time,c):
|
|
||||||
|
async def remindTask(self, n, up, delta_time, c):
|
||||||
|
|
||||||
await asyncio.sleep(delta_time)
|
await asyncio.sleep(delta_time)
|
||||||
await self.message(c,'[\x036radio\x0f] beep boop, {} is here to remind you that {}\'s show is coming up in about 30 seconds!'.format(n,up['name']))
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036radio\x0f] beep boop, {} is here to remind you that {}'s show is coming up in about 30 seconds!".format(
|
||||||
|
n, up["name"]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.tildebot = True
|
self.tildebot = True
|
||||||
self.rreminders = {}
|
self.rreminders = {}
|
||||||
self.cmd['un'] = upnext
|
self.cmd["un"] = upnext
|
||||||
self.cmd['upnext'] = upnext
|
self.cmd["upnext"] = upnext
|
||||||
self.cmd['radioremind'] = radioremind
|
self.cmd["radioremind"] = radioremind
|
||||||
self.help['radioremind'] = ['radioremind [where] - set a reminder that someone will stream','oh no i forgot what to put here!']
|
self.help["radioremind"] = [
|
||||||
#self.help['upnext'] = ['upnext - get who will be up next on tilderadio\'s schedule','noice moosic']
|
"radioremind [where] - set a reminder that someone will stream",
|
||||||
self.cmd['nowplaying'] = nowplaying
|
"oh no i forgot what to put here!",
|
||||||
#self.help['nowplaying'] = ['nowplaying - when radiobot is dead use this instead!','lol']
|
]
|
||||||
|
# self.help['upnext'] = ['upnext - get who will be up next on tilderadio\'s schedule','noice moosic']
|
||||||
|
self.cmd["nowplaying"] = nowplaying
|
||||||
|
# self.help['nowplaying'] = ['nowplaying - when radiobot is dead use this instead!','lol']
|
||||||
|
|
|
@ -1,30 +1,44 @@
|
||||||
|
|
||||||
# '[\x0303Pronouns\x03] Pronouns for xfnw: he/him'
|
# '[\x0303Pronouns\x03] Pronouns for xfnw: he/him'
|
||||||
|
|
||||||
|
|
||||||
async def scraper(self,c,n,m):
|
async def scraper(self, c, n, m):
|
||||||
m = m.split(' ')
|
m = m.split(" ")
|
||||||
if len(m) > 4:
|
if len(m) > 4:
|
||||||
if m.pop(0) in ('[\x0303Pronouns\x03]', '[Pronouns]') and m.pop(0) == 'Pronouns' and m.pop(0) == 'for':
|
if (
|
||||||
|
m.pop(0) in ("[\x0303Pronouns\x03]", "[Pronouns]")
|
||||||
|
and m.pop(0) == "Pronouns"
|
||||||
|
and m.pop(0) == "for"
|
||||||
|
):
|
||||||
person = m.pop(0)[:-1]
|
person = m.pop(0)[:-1]
|
||||||
pronouns = ' '.join(m)
|
pronouns = " ".join(m)
|
||||||
|
|
||||||
print('found pronouns of {}: {}'.format(person,pronouns))
|
print("found pronouns of {}: {}".format(person, pronouns))
|
||||||
self.pronoundb.upsert(dict(nick=person,pronouns=pronouns),['nick'])
|
self.pronoundb.upsert(dict(nick=person, pronouns=pronouns), ["nick"])
|
||||||
|
|
||||||
async def getPronouns(self,c,n,m):
|
|
||||||
|
async def getPronouns(self, c, n, m):
|
||||||
m = m.strip()
|
m = m.strip()
|
||||||
if not m:
|
if not m:
|
||||||
m = n
|
m = n
|
||||||
pronoun = self.pronoundb.find_one(nick=m)
|
pronoun = self.pronoundb.find_one(nick=m)
|
||||||
if pronoun:
|
if pronoun:
|
||||||
await self.message(c,'[\x036scrape\x0f] Pronouns for {}: {}'.format(pronoun['nick'],pronoun['pronouns']))
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036scrape\x0f] Pronouns for {}: {}".format(
|
||||||
|
pronoun["nick"], pronoun["pronouns"]
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.message(c,'[\x036scrape\x0f] sorry i could not find {}\'s pronouns. (i scrape pronouns from logs, you dont need to set them :3 )'.format(m))
|
await self.message(
|
||||||
|
c,
|
||||||
|
"[\x036scrape\x0f] sorry i could not find {}'s pronouns. (i scrape pronouns from logs, you dont need to set them :3 )".format(
|
||||||
|
m
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.rawm['scraper'] = scraper
|
self.rawm["scraper"] = scraper
|
||||||
self.pronoundb = self.db['pronouns']
|
self.pronoundb = self.db["pronouns"]
|
||||||
|
|
||||||
self.cmd['pronouns'] = getPronouns
|
|
||||||
|
|
||||||
|
self.cmd["pronouns"] = getPronouns
|
||||||
|
|
|
@ -1,72 +1,83 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
async def on_join(self,channel,person):
|
|
||||||
|
async def on_join(self, channel, person):
|
||||||
if person in self.users:
|
if person in self.users:
|
||||||
user = self.users[person]
|
user = self.users[person]
|
||||||
self.userdb.insert_ignore(dict(user),['id'])
|
self.userdb.insert_ignore(dict(user), ["id"])
|
||||||
|
|
||||||
async def on_all(self,wtime=100):
|
|
||||||
print('will index users in ',wtime)
|
async def on_all(self, wtime=100):
|
||||||
|
print("will index users in ", wtime)
|
||||||
await asyncio.sleep(wtime)
|
await asyncio.sleep(wtime)
|
||||||
print('started indexing users')
|
print("started indexing users")
|
||||||
users = self.users.copy()
|
users = self.users.copy()
|
||||||
for person in users:
|
for person in users:
|
||||||
user = self.users[person]
|
user = self.users[person]
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
self.userdb.insert_ignore(dict(user),['id'])
|
self.userdb.insert_ignore(dict(user), ["id"])
|
||||||
print('done')
|
print("done")
|
||||||
|
|
||||||
|
|
||||||
async def maskfind(self,c,n,m):
|
async def maskfind(self, c, n, m):
|
||||||
host = nick = ident = '%'
|
host = nick = ident = "%"
|
||||||
m = m.strip().replace("*","%").split('@')
|
m = m.strip().replace("*", "%").split("@")
|
||||||
host = m.pop()
|
host = m.pop()
|
||||||
if len(m) > 0:
|
if len(m) > 0:
|
||||||
ni = m.pop().split('!')
|
ni = m.pop().split("!")
|
||||||
ident = ni.pop()
|
ident = ni.pop()
|
||||||
if len(ni) > 0:
|
if len(ni) > 0:
|
||||||
nick = ni.pop()
|
nick = ni.pop()
|
||||||
|
|
||||||
|
alts = [
|
||||||
alts = ["{}!{}@{}".format(i['nickname'],i['username'][:1]+"\u200c"+i['username'][1:],i['hostname']) for i in self.userdb.find(hostname={'like':host},username={'like':ident},nickname={'like':nick},order_by='-id')]
|
"{}!{}@{}".format(
|
||||||
falt=' '.join([i[:1]+'\u200c'+i[1:] for i in list(set(alts))])
|
i["nickname"],
|
||||||
|
i["username"][:1] + "\u200c" + i["username"][1:],
|
||||||
|
i["hostname"],
|
||||||
|
)
|
||||||
|
for i in self.userdb.find(
|
||||||
|
hostname={"like": host},
|
||||||
|
username={"like": ident},
|
||||||
|
nickname={"like": nick},
|
||||||
|
order_by="-id",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
falt = " ".join([i[:1] + "\u200c" + i[1:] for i in list(set(alts))])
|
||||||
if len(falt) > 250:
|
if len(falt) > 250:
|
||||||
self.more[c] = falt[200:]
|
self.more[c] = falt[200:]
|
||||||
falt = falt[:200]+' (more)'
|
falt = falt[:200] + " (more)"
|
||||||
await self.message(c,'[\x036usrinfo\x0f] masks: {}'.format(falt))
|
await self.message(c, "[\x036usrinfo\x0f] masks: {}".format(falt))
|
||||||
|
|
||||||
|
|
||||||
|
async def findalt(self, c, n, m):
|
||||||
|
|
||||||
|
|
||||||
async def findalt(self,c,n,m):
|
|
||||||
m = m.strip()
|
m = m.strip()
|
||||||
user = self.userdb.find_one(nickname={'like':m},order_by='-id')
|
user = self.userdb.find_one(nickname={"like": m}, order_by="-id")
|
||||||
if user == None:
|
if user == None:
|
||||||
await self.message(c,'[\x036usrinfo\x0f] I could not find that user :(')
|
await self.message(c, "[\x036usrinfo\x0f] I could not find that user :(")
|
||||||
# check if identd
|
# check if identd
|
||||||
if user['username'][0] == '~':
|
if user["username"][0] == "~":
|
||||||
# not identd
|
# not identd
|
||||||
alts = [i['nickname'] for i in self.userdb.find(hostname=user['hostname'])]
|
alts = [i["nickname"] for i in self.userdb.find(hostname=user["hostname"])]
|
||||||
else:
|
else:
|
||||||
alts = [i['nickname'] for i in self.userdb.find(username=user['username'])]
|
alts = [i["nickname"] for i in self.userdb.find(username=user["username"])]
|
||||||
if len(alts) < 2:
|
if len(alts) < 2:
|
||||||
await self.message(c,'[\x036usrinfo\x0f] I could not find any alts :(')
|
await self.message(c, "[\x036usrinfo\x0f] I could not find any alts :(")
|
||||||
return
|
return
|
||||||
falt=' '.join([i[:1]+'\u200c'+i[1:] for i in sorted(list(set(alts)))])
|
falt = " ".join([i[:1] + "\u200c" + i[1:] for i in sorted(list(set(alts)))])
|
||||||
if len(falt) > 250:
|
if len(falt) > 250:
|
||||||
self.more[c] = falt[200:]
|
self.more[c] = falt[200:]
|
||||||
falt = falt[:200]+' (more)'
|
falt = falt[:200] + " (more)"
|
||||||
await self.message(c,'[\x036usrinfo\x0f] alts: {}'.format(falt))
|
await self.message(c, "[\x036usrinfo\x0f] alts: {}".format(falt))
|
||||||
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.userdb = self.db['user']
|
self.userdb = self.db["user"]
|
||||||
|
|
||||||
if not self.userdb.find_one(sync='yes'):
|
if not self.userdb.find_one(sync="yes"):
|
||||||
self.userdb.insert(dict(sync='yes'))
|
self.userdb.insert(dict(sync="yes"))
|
||||||
asyncio.get_event_loop().create_task(on_all(self))
|
asyncio.get_event_loop().create_task(on_all(self))
|
||||||
|
|
||||||
self.help['findalt'] = ['findalt <nick> - find out who someone\'s alts are',';p']
|
self.help["findalt"] = ["findalt <nick> - find out who someone's alts are", ";p"]
|
||||||
self.cmd['findalt'] = findalt
|
self.cmd["findalt"] = findalt
|
||||||
self.help['maskfind'] = ['maskfind <mask> - search masks','OW']
|
self.help["maskfind"] = ["maskfind <mask> - search masks", "OW"]
|
||||||
self.cmd['maskfind'] = maskfind
|
self.cmd["maskfind"] = maskfind
|
||||||
|
|
Loading…
Reference in New Issue