Compare commits

...

7 Commits

11 changed files with 30 additions and 28 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
drastikbot

8
flake.lock generated
View File

@@ -17,16 +17,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1638239011,
"narHash": "sha256-AjhmbT4UBlJWqxY0ea8a6GU2C2HdKUREkG43oRr3TZg=",
"lastModified": 1739758141,
"narHash": "sha256-uq6A2L7o1/tR6VfmYhZWoVAwb3gTy7j4Jx30MIrH0rE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31",
"rev": "c618e28f70257593de75a7044438efc1c1fc0791",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "21.11",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}

View File

@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/21.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};
@@ -10,7 +10,7 @@
supportedSystems = with flake-utils.lib.system; [ x86_64-linux i686-linux aarch64-linux ];
in {
overlay = final: prev: {
drastikbot = prev.python3Packages.buildPythonApplication rec {
drastikbot = prev.python311.pkgs.buildPythonApplication rec {
pname = "drastikbot";
version = "v2.1";
@@ -29,8 +29,8 @@
cp -r $src/src/* $out
mkdir -p $out/bin
makeWrapper ${prev.python3}/bin/python3 $out/bin/drastikbot \
--prefix PYTHONPATH : ${with prev.python3Packages; makePythonPath [requests beautifulsoup4]} \
makeWrapper ${prev.python311}/bin/python3 $out/bin/drastikbot \
--prefix PYTHONPATH : ${with prev.python311.pkgs; makePythonPath [requests beautifulsoup4]} \
--add-flags "$out/drastikbot.py"
'';
};

View File

@@ -74,13 +74,13 @@ def parser():
" already exists.")
conf_dir = str(path.expanduser().resolve())
else:
path = Path('~/.drastikbot').expanduser()
path = Path('./drastikbot').expanduser()
if not path.is_dir():
try:
path.mkdir(parents=True, exist_ok=False)
except FileExistsError:
sys.exit("[Error] Making configuration directory at"
" '~/.drastikbot' failed. Another file with that name"
" './drastikbot' failed. Another file with that name"
" already exists.")
conf_dir = str(path)

View File

@@ -145,7 +145,7 @@ class Drastikbot():
# statement below.
if multipart:
time.sleep(self.var.msg_delay)
tr = m_len - 2 - len(' '.join(cmds).encode('utf-8')) - remainder
tr = m_len - 2 - len(' '.join(cmds).encode('utf-8')) - remainder - 1
t = text.encode('utf-8')[tr:]
self.send(cmds, t)

View File

@@ -44,14 +44,14 @@ class Module:
def main(i, irc):
values = i.msg_nocmd.split('d')
if len(values) != 2:
irc.notice(i.channel, f"Usage: {i.cmd_prefix}roll <n>d<s>")
irc.privmsg(i.channel, f"Usage: {i.cmd_prefix}roll <n>d<s>")
return
n_dice = int(values[0])
n_sides = int(values[1])
if n_dice > 1000 or n_sides > 1000:
irc.notice(i.channel, f"{i.nickname}: Too many dice or sides given.")
irc.privmsg(i.channel, f"{i.nickname}: Too many dice or sides given.")
return
results = [random.randint(1, n_sides) for i in range(n_dice)]

View File

@@ -84,13 +84,13 @@ def is_hidden(i, module_name):
def module_checks(i, irc, module):
if module not in i.modules.keys():
irc.notice(i.channel, f"Help: `{module}' is not an imported module.")
irc.privmsg(i.channel, f"Help: `{module}' is not an imported module.")
return False
try:
module_bl = irc.var.modules_obj["blacklist"][module]
if module_bl and i.channel in module_bl:
irc.notice(i.channel, f"Help: This module has been disabled.")
irc.privmsg(i.channel, f"Help: This module has been disabled.")
return False
except KeyError:
pass # No blacklist, move on
@@ -98,14 +98,14 @@ def module_checks(i, irc, module):
try:
module_wl = irc.var.modules_obj["whitelist"][module]
if module_wl and i.channel not in module_wl:
irc.notice(i.channel, f"Help: This module has been disabled.")
irc.privmsg(i.channel, f"Help: This module has been disabled.")
return False
except KeyError:
pass # No whitelist, move on
module_c = i.modules[module].Module()
if not hasattr(module_c, "manual"):
irc.notice(i.channel, "Help: This module does not have a manual.")
irc.privmsg(i.channel, "Help: This module does not have a manual.")
return False
return True
@@ -128,7 +128,7 @@ def module_help(i, irc, module):
t = f"\x0311{module}\x0F: {commands}{info}"
t += f" | Use: {i.cmd_prefix}help <module> <command> for command info."
irc.notice(i.channel, t)
irc.privmsg(i.channel, t)
def command_help(i, irc, module, command):
@@ -138,17 +138,17 @@ def command_help(i, irc, module, command):
module_c = i.modules[module].Module()
if not hasattr(module_c, "commands"):
irc.notice(i.channel, "Help: This module does not provide commands.")
irc.privmsg(i.channel, "Help: This module does not provide commands.")
return
if "bot_commands" not in module_c.manual:
irc.notice(i.channel, "Help: No manual entry for this command ")
irc.privmsg(i.channel, "Help: No manual entry for this command ")
return
command_manual = module_c.manual["bot_commands"]
if command not in command_manual:
irc.notice(i.channel, "Help: No manual entry for this command.")
irc.privmsg(i.channel, "Help: No manual entry for this command.")
return
command_entry = command_manual[command]
@@ -172,7 +172,7 @@ def command_help(i, irc, module, command):
t = " | ".join(t)
t = f"{command}: {t}"
irc.notice(i.channel, t)
irc.privmsg(i.channel, t)
def module_list(i, irc):
@@ -185,7 +185,7 @@ def module_list(i, irc):
m = itertools.chain(m1, m2)
t = "Help: " + ", ".join(sorted(m))
t += f" | Use: {i.cmd_prefix}help <module> for module info."
irc.notice(i.channel, t)
irc.privmsg(i.channel, t)
def main(i, irc):
@@ -198,6 +198,6 @@ def main(i, irc):
command_help(i, irc, argv[0], argv[1])
else:
m = f"Usage: {i.cmd_prefix}help [module] [command]"
irc.notice(i.channel, m)
irc.privmsg(i.channel, m)
else:
module_list(i, irc)

View File

@@ -37,5 +37,5 @@ def main(i, irc):
elif i.cmd == "source":
if not i.msg_nocmd or i.msg_nocmd == irc.var.curr_nickname:
m = ("\x0305,01drastikbot + drastikbot_modules + dailybuild_modules\x0F"
" : \\x0311https://git.neet.dev/zuckerberg/dailybuild_modules\\x0F")
" : \x0311https://git.neet.dev/zuckerberg/dailybuild_modules\x0F")
irc.privmsg(i.channel, m)

View File

@@ -154,11 +154,11 @@ def listquotes(channel, nickname, dbc, irc):
data += m
if not rest and not sbn:
irc.notice(nickname, f"{logo}: No results.")
irc.privmsg(nickname, f"{logo}: No results.")
else:
pomf_url = listquotes_pomf(data)
m = f"{logo}: Your quotes can be found here: {pomf_url}"
irc.notice(nickname, m)
irc.privmsg(nickname, m)
def listquotes_pomf(data):

View File

@@ -212,4 +212,4 @@ def main(i, irc):
# Truncate the output just in case. We can't send 512 bytes anyway.
m = m[:512]
irc.notice(receiver, m)
irc.privmsg(receiver, m)

View File

@@ -269,6 +269,7 @@ def twitter(url):
hosts_d = {
"youtube.com": youtube,
"youtu.be": youtube,
"m.youtube.com": youtube,
"lainchan.org": lainchan,
"i.imgur.com": imgur,
"imgur.com": imgur,