added dice and choose command, fixed up ctcp ping
This commit is contained in:
parent
954f2085be
commit
6f06ccd1a0
48
commands.py
48
commands.py
@ -3,6 +3,7 @@ from irctokens import build
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
import random
|
||||
|
||||
|
||||
class Command:
|
||||
@ -100,6 +101,10 @@ class Command:
|
||||
command = "quit"
|
||||
elif cmd.startswith("echo "):
|
||||
command = "echo"
|
||||
elif cmd.startswith("roll ") or cmd == "roll":
|
||||
command = "dice"
|
||||
elif cmd.startswith("pick ") or cmd.startswith("choose "):
|
||||
command = "choose"
|
||||
elif cmd.startswith("yt ") or self.YouTube.match_urls(self.YouTube, cmd) != []:
|
||||
command = "yt"
|
||||
needs_prefix = False
|
||||
@ -139,25 +144,30 @@ class Command:
|
||||
"""CTCP responses"""
|
||||
notice = self.notice
|
||||
ctcp = cmd[1:]
|
||||
if ctcp.startswith("PING"):
|
||||
ctcp_upper = ctcp.upper()
|
||||
if ctcp_upper.startswith("PING"):
|
||||
ctcp = (
|
||||
"\x01PING"
|
||||
+ ("" if 1 == len(ctcp.split(" ")) else " ")
|
||||
+ " ".join(ctcp.split(" ")[1:])
|
||||
)
|
||||
if not ctcp.endswith("\x01"):
|
||||
ctcp = ctcp + "\x01"
|
||||
print(ctcp)
|
||||
self.notice(ctcp)
|
||||
ctcp = ctcp.upper()
|
||||
if ctcp.startswith("SOURCE"):
|
||||
if ctcp_upper.startswith("SOURCE"):
|
||||
self.notice("\x01SOURCE " + self.config.self.source + "\x01")
|
||||
elif ctcp.startswith("VERSION"):
|
||||
elif ctcp_upper.startswith("VERSION"):
|
||||
self.notice(f"\x01VERSION {self.getversion()}\x01")
|
||||
elif ctcp.startswith("FINGER"):
|
||||
elif ctcp_upper.startswith("FINGER"):
|
||||
self.notice(
|
||||
f"\x01FINGER {self.config.self.nick} version {self.getversion()} ({self.config.self.source})\x01"
|
||||
)
|
||||
elif ctcp.startswith("USERINFO"):
|
||||
elif ctcp_upper.startswith("USERINFO"):
|
||||
self.notice(
|
||||
"\x01USERINFO crude IRC bot, originally made by jan6, as bot6 (https://tildegit.org/jan6/bot6)\x01"
|
||||
)
|
||||
elif ctcp.startswith("CLIENTINFO"):
|
||||
elif ctcp_upper.startswith("CLIENTINFO"):
|
||||
self.notice("\x01CLIENTINFO USERINFO PING SOURCE FINGER VERSION\x01")
|
||||
|
||||
@adm
|
||||
@ -201,6 +211,30 @@ class Command:
|
||||
"""simple echo command"""
|
||||
mesg("\x7f" + cmd.split(" ", 1)[1])
|
||||
|
||||
@cmd
|
||||
def choose(self, prefix, cmd, pm, line, admin, mesg):
|
||||
f"""simple random choice command, "{self.config.cmd.prefixes[0]}choose A B C..." """
|
||||
mesg("I choose: " + str(random.choice(cmd.split(" ", 1)[1].split(" "))))
|
||||
|
||||
@cmd
|
||||
def dice(self, prefix, cmd, pm, line, admin, mesg):
|
||||
f"""simple dice command, "{self.config.cmd.prefixes[0]}roll [N[d[M]]]" where N is number of dice, and M is number of faces"""
|
||||
cmd = cmd.split(" ", 1)[1]
|
||||
amount, faces = 1, 6
|
||||
try:
|
||||
amount = 0 + int(cmd.split("d", 1)[0])
|
||||
faces = 0 + int(cmd.split("d", 1)[1])
|
||||
except:
|
||||
pass
|
||||
if not str(amount).isnumeric() or amount > 100:
|
||||
amount = 1
|
||||
if not str(faces).isnumeric() or faces > 100:
|
||||
faces = 6
|
||||
mesg(
|
||||
f"rolling {amount}d{faces}: "
|
||||
+ str([random.choice([i for i in range(faces)]) for n in range(amount)])
|
||||
)
|
||||
|
||||
@cmd
|
||||
def version(self, prefix, cmd, pm, line, admin, mesg):
|
||||
"""version"""
|
||||
|
Loading…
Reference in New Issue
Block a user