ircrobots updates
This commit is contained in:
parent
865f9b8b46
commit
e2eb052594
|
@ -59,4 +59,4 @@ docs/_build/
|
||||||
target/
|
target/
|
||||||
|
|
||||||
venv/
|
venv/
|
||||||
account.ini
|
config.ini
|
||||||
|
|
|
@ -14,15 +14,16 @@ deps:
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
1. adjust config.ini
|
2. `cp config.ini{.sample,}`
|
||||||
1. start the bot
|
3. edit config.ini
|
||||||
|
4. start the bot
|
||||||
venv/bin/python3 tracer.py
|
venv/bin/python3 tracer.py
|
||||||
|
|
||||||
### daemonization
|
### daemonization
|
||||||
|
|
||||||
1. adjust tracer.service
|
|
||||||
1. `mkdir -p ~/.config/systemd/user`
|
1. `mkdir -p ~/.config/systemd/user`
|
||||||
1. `cp tracer.service ~/.config/systemd/user/`
|
1. `cp tracer.service ~/.config/systemd/user/`
|
||||||
|
1. adjust ~/.config/systemd/user/tracer.service as needed
|
||||||
1. `systemctl --user daemon-reload`
|
1. `systemctl --user daemon-reload`
|
||||||
1. `systemctl --user enable --now tracer`
|
1. `systemctl --user enable --now tracer`
|
||||||
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
[nickserv]
|
|
||||||
username = bensbots
|
|
||||||
password = my super secret password
|
|
||||||
|
|
|
@ -5,3 +5,6 @@ nick = tracer
|
||||||
port = 6667
|
port = 6667
|
||||||
tls = false
|
tls = false
|
||||||
|
|
||||||
|
[sasl]
|
||||||
|
username = tracer
|
||||||
|
password = my super secret password
|
|
@ -1,2 +1,2 @@
|
||||||
tracery==0.1.1
|
tracery==0.1.1
|
||||||
ircrobots==0.3.7
|
ircrobots==0.6.1
|
||||||
|
|
57
tracer.py
57
tracer.py
|
@ -14,21 +14,21 @@ import random
|
||||||
import traceback
|
import traceback
|
||||||
import tracery
|
import tracery
|
||||||
|
|
||||||
HELPTEXT = "helo i'm a tracery bot that makes cool things from tracery grammars in your ~/.tracery. see http://tracery.io for more info"
|
HELP_TEXT = "helo i'm a tracery bot that makes cool things from tracery grammars in your ~/.tracery. see " \
|
||||||
REPOLINK = "https://tildegit.org/ben/tracer"
|
"https://tracery.io for more info "
|
||||||
|
REPO_LINK = "https://tildegit.org/ben/tracer"
|
||||||
|
|
||||||
DB = {}
|
DB = {}
|
||||||
|
|
||||||
# read configuration
|
# read configuration
|
||||||
config = configparser.ConfigParser(
|
if not os.path.isfile("config.ini"):
|
||||||
converters={"list": lambda x: [i.strip() for i in x.split(",")]}
|
print("you must create a config.ini file")
|
||||||
)
|
exit(1)
|
||||||
config.read("config.ini")
|
|
||||||
config = config["irc"]
|
|
||||||
|
|
||||||
account = configparser.ConfigParser()
|
parser = configparser.ConfigParser()
|
||||||
account.read("account.ini")
|
parser.read("config.ini")
|
||||||
account = account["nickserv"]
|
config = parser["irc"]
|
||||||
|
account = parser["sasl"]
|
||||||
|
|
||||||
|
|
||||||
def grammar(rules):
|
def grammar(rules):
|
||||||
|
@ -101,29 +101,30 @@ def fuse(argv):
|
||||||
|
|
||||||
|
|
||||||
def think(line):
|
def think(line):
|
||||||
words = line.params[1].split(" ")
|
command, *words = line.params[1].split(" ")
|
||||||
if words[0] == "!!list":
|
|
||||||
|
if command == "!!list":
|
||||||
return " ".join(DB)
|
return " ".join(DB)
|
||||||
elif words[0] == "!!source":
|
elif command == "!!source":
|
||||||
return REPOLINK
|
return REPO_LINK
|
||||||
elif words[0] in ["!!help", "!botlist"]:
|
elif command in ["!!help", "!botlist"]:
|
||||||
return HELPTEXT
|
return HELP_TEXT
|
||||||
elif words[0] == "!!fuse":
|
elif command == "!!fuse":
|
||||||
if "|" in words:
|
if "|" in words:
|
||||||
w = words.index("|")
|
w = words.index("|")
|
||||||
res = fuse(words[1:w])
|
res = fuse(words[:w])
|
||||||
if res:
|
if res:
|
||||||
return " ".join(words[w + 1 :]) + " " + res
|
return " ".join(words[w + 1:]) + " " + res
|
||||||
else:
|
else:
|
||||||
res = fuse(words[1:])
|
res = fuse(words)
|
||||||
if res:
|
if res:
|
||||||
return res
|
return res
|
||||||
elif words[0].startswith("!!"):
|
elif command.startswith("!!"):
|
||||||
res = generate(words[0][2:])
|
res = generate(command[2:])
|
||||||
if res:
|
if res:
|
||||||
if "|" in words:
|
if "|" in words:
|
||||||
w = words.index("|")
|
w = words.index("|")
|
||||||
return " ".join(words[w + 1 :]) + " " + res
|
return " ".join(words[w + 1:]) + " " + res
|
||||||
else:
|
else:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -134,8 +135,8 @@ class Server(BaseServer):
|
||||||
|
|
||||||
async def line_read(self, line: Line):
|
async def line_read(self, line: Line):
|
||||||
print(f"{self.name} < {line.format()}")
|
print(f"{self.name} < {line.format()}")
|
||||||
|
|
||||||
if line.command == "001":
|
if line.command == "001":
|
||||||
await self.send(build("JOIN", [",".join(config.getlist("channels"))]))
|
|
||||||
await self.send(build("MODE", [self.nickname, "+B"]))
|
await self.send(build("MODE", [self.nickname, "+B"]))
|
||||||
|
|
||||||
if line.command == "INVITE":
|
if line.command == "INVITE":
|
||||||
|
@ -146,10 +147,11 @@ class Server(BaseServer):
|
||||||
and self.has_channel(line.params[0])
|
and self.has_channel(line.params[0])
|
||||||
and self.has_user(line.hostmask.nickname)
|
and self.has_user(line.hostmask.nickname)
|
||||||
and len(line.params[1].split(" ")) > 0
|
and len(line.params[1].split(" ")) > 0
|
||||||
and not line.hostmask is None
|
and line.hostmask is not None
|
||||||
and not self.casefold(line.hostmask.nickname) == self.nickname_lower
|
and not self.casefold(line.hostmask.nickname) == self.nickname_lower
|
||||||
and not ("batch" in line.tags and line.tags["batch"] == "1")
|
and not ("batch" in line.tags and line.tags["batch"] == "1")
|
||||||
and not "inspircd.org/bot" in line.tags
|
and "inspircd.org/bot" not in line.tags
|
||||||
|
and line.params[1].startswith("!")
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
response = think(line)
|
response = think(line)
|
||||||
|
@ -173,9 +175,10 @@ async def main():
|
||||||
port=config.getint("port"),
|
port=config.getint("port"),
|
||||||
tls=config.getboolean("tls"),
|
tls=config.getboolean("tls"),
|
||||||
sasl=SASLUserPass(account["username"], account["password"]),
|
sasl=SASLUserPass(account["username"], account["password"]),
|
||||||
|
autojoin=[config["channels"]]
|
||||||
)
|
)
|
||||||
bot = Bot()
|
bot = Bot()
|
||||||
await bot.add_server("tilde", params)
|
await bot.add_server(config["server"], params)
|
||||||
await bot.run()
|
await bot.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ After=tracer.service
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
WorkingDirectory=/home/ben/workspace/tracer
|
WorkingDirectory=/home/ben/workspace/tracer
|
||||||
ExecStart=/usr/bin/python3 -u tracer.py
|
ExecStart=/home/ben/workspace/tracer/venv/bin/python3 -u tracer.py
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
StartLimitInterval=60s
|
StartLimitInterval=60s
|
||||||
|
@ -13,4 +13,3 @@ StartLimitBurst=3
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue