ircrobots updates

master
Ben Harris 7 months ago
parent 865f9b8b46
commit e2eb052594
  1. 2
      .gitignore
  2. 7
      README.md
  3. 4
      account.ini.sample
  4. 3
      config.ini.sample
  5. 2
      requirements.txt
  6. 69
      tracer.py
  7. 3
      tracer.service

2
.gitignore vendored

@ -59,4 +59,4 @@ docs/_build/
target/
venv/
account.ini
config.ini

@ -14,15 +14,16 @@ deps:
. venv/bin/activate
pip install -r requirements.txt
1. adjust config.ini
1. start the bot
2. `cp config.ini{.sample,}`
3. edit config.ini
4. start the bot
venv/bin/python3 tracer.py
### daemonization
1. adjust tracer.service
1. `mkdir -p ~/.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 enable --now tracer`

@ -1,4 +0,0 @@
[nickserv]
username = bensbots
password = my super secret password

@ -5,3 +5,6 @@ nick = tracer
port = 6667
tls = false
[sasl]
username = tracer
password = my super secret password

@ -1,2 +1,2 @@
tracery==0.1.1
ircrobots==0.3.7
ircrobots==0.6.1

@ -14,21 +14,21 @@ import random
import traceback
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"
REPOLINK = "https://tildegit.org/ben/tracer"
HELP_TEXT = "helo i'm a tracery bot that makes cool things from tracery grammars in your ~/.tracery. see " \
"https://tracery.io for more info "
REPO_LINK = "https://tildegit.org/ben/tracer"
DB = {}
# read configuration
config = configparser.ConfigParser(
converters={"list": lambda x: [i.strip() for i in x.split(",")]}
)
config.read("config.ini")
config = config["irc"]
if not os.path.isfile("config.ini"):
print("you must create a config.ini file")
exit(1)
account = configparser.ConfigParser()
account.read("account.ini")
account = account["nickserv"]
parser = configparser.ConfigParser()
parser.read("config.ini")
config = parser["irc"]
account = parser["sasl"]
def grammar(rules):
@ -101,29 +101,30 @@ def fuse(argv):
def think(line):
words = line.params[1].split(" ")
if words[0] == "!!list":
command, *words = line.params[1].split(" ")
if command == "!!list":
return " ".join(DB)
elif words[0] == "!!source":
return REPOLINK
elif words[0] in ["!!help", "!botlist"]:
return HELPTEXT
elif words[0] == "!!fuse":
elif command == "!!source":
return REPO_LINK
elif command in ["!!help", "!botlist"]:
return HELP_TEXT
elif command == "!!fuse":
if "|" in words:
w = words.index("|")
res = fuse(words[1:w])
res = fuse(words[:w])
if res:
return " ".join(words[w + 1 :]) + " " + res
return " ".join(words[w + 1:]) + " " + res
else:
res = fuse(words[1:])
res = fuse(words)
if res:
return res
elif words[0].startswith("!!"):
res = generate(words[0][2:])
elif command.startswith("!!"):
res = generate(command[2:])
if res:
if "|" in words:
w = words.index("|")
return " ".join(words[w + 1 :]) + " " + res
return " ".join(words[w + 1:]) + " " + res
else:
return res
@ -134,22 +135,23 @@ class Server(BaseServer):
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
await self.send(build("JOIN", [",".join(config.getlist("channels"))]))
await self.send(build("MODE", [self.nickname, "+B"]))
if line.command == "INVITE":
await self.send(build("JOIN", [line.params[1]]))
if (
line.command == "PRIVMSG"
and self.has_channel(line.params[0])
and self.has_user(line.hostmask.nickname)
and len(line.params[1].split(" ")) > 0
and not line.hostmask is None
and not self.casefold(line.hostmask.nickname) == self.nickname_lower
and not ("batch" in line.tags and line.tags["batch"] == "1")
and not "inspircd.org/bot" in line.tags
line.command == "PRIVMSG"
and self.has_channel(line.params[0])
and self.has_user(line.hostmask.nickname)
and len(line.params[1].split(" ")) > 0
and line.hostmask is not None
and not self.casefold(line.hostmask.nickname) == self.nickname_lower
and not ("batch" in line.tags and line.tags["batch"] == "1")
and "inspircd.org/bot" not in line.tags
and line.params[1].startswith("!")
):
try:
response = think(line)
@ -173,9 +175,10 @@ async def main():
port=config.getint("port"),
tls=config.getboolean("tls"),
sasl=SASLUserPass(account["username"], account["password"]),
autojoin=[config["channels"]]
)
bot = Bot()
await bot.add_server("tilde", params)
await bot.add_server(config["server"], params)
await bot.run()

@ -5,7 +5,7 @@ After=tracer.service
[Service]
Type=simple
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
RestartSec=5
StartLimitInterval=60s
@ -13,4 +13,3 @@ StartLimitBurst=3
[Install]
WantedBy=default.target

Loading…
Cancel
Save