Some initial scribblings.

This commit is contained in:
zgrep 2018-07-19 18:40:41 -04:00
parent c24ab434fc
commit bfffde1957
7 changed files with 101 additions and 3 deletions

25
bin/connect Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
alias logdate=date +'%Y-%m-%d %H:%M:%S'
cd "${1:-/home/happybot}"
export PATH="$(pwd)/bin:$PATH"
if test -e input; then rm input; fi
if test -e /tmp/happybot; then rm -r /tmp/happybot; fi
mkfifo input
mkdir /tmp/happybot
if hateweek/isnow; then
echo 'hatebot' > /tmp/happybot/nick;
else
echo 'happybot' > /tmp/happybot/nick;
fi
tail -f input | while read -r line; do
printf '%s :%s %s\n' "$(logdate)" "$(cat /tmp/happybot/nick)" "$line" >> log.txt
printf '%s\n' "$line"
done | openssl s_client -quiet -connect irc.freenode.net:6697 | while read -r line; do
printf '%s %s\n' "$(logdate)" "$line" >> log.txt
callirc "$line" &
done

5
bin/hateweek/end Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
sed -i 's/0/1/' bin/hateweek/isnow
raw 'NICK happybot'
privmsg '#offtopia' 'Hate how hateweek is over!'

3
bin/hateweek/isnow Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
exit 1

5
bin/hateweek/start Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
sed -i 's/1/0/' bin/hateweek/isnow
raw 'NICK hatebot'
privmsg '#offtopia' "Hateweek is here! Hate how it's only once a year!"

40
readme.md Normal file
View File

@ -0,0 +1,40 @@
`input`:
- The named pipe to talk as the bot.
`bin/`:
- `raw` - Sends `$1` to freenode.
- `reply` - Uses env vars to send message `$@`.
- `result` - Like reply, but does not prepend `nick:`.
- `privmsg` - Sends privmsg to `$1`, with message `shift;$@`.
- `notice` - Sends privmsg to `$1`, with message `shift;$@`.
- `action` - Sends ctcp action to `$1`, with message `shift;$@`.
- `ctcp` - Sends a ctcp query, returns the response.
- `connect` - Connects to IRC, calls commands in `irc/`, listens to `input`,
and writes to log the file.
- `hateweek/start` - Begins hateweek mode.
- `hateweek/end` - Ends hateweek mode.
- `hateweek/isnow` - Check to see if hateweek is now (returns 0 if now, 1 if
not now).
`log.txt`:
- The single file that has all of the logs.
- Uses the IRC format with a timestamp prepended.
`irc/`:
- IRC commands are run as shell commands.
- `bin/` is in their `PATH`.
- Set up env vars before calling various functions.
- Add data to log files if needed.
Env vars:
- `$acct`: NickServ account name, or `\*`.
- `$nick`
- `$cmd`
- `$where`
- `$msg`
`/tmp/happybot/`:
- directory for temporary information
- `nick` - The bot's nick.
- `acct` - Look up account name by nick.
- Either a directory, or a file.

1
sudoers Normal file
View File

@ -0,0 +1 @@
happybot ALL=(root) NOPASSWD: /sbin/rc-service happybot

25
xed.py
View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3
from lark import Lark, Transformer, ParseError, Tree
parser = Lark(r'''
@ -13,7 +12,7 @@ parser = Lark(r'''
| bracketliteral "-" bracketliteral
brackets : "[" range+ "]" -> either
char : /[^\\\[\]\{\}\(\)\|\^~\?]/
char : /[^\\\[\]\{\}\(\)\|\^~\?!]/
| "\\" /\D/
| //
@ -27,6 +26,9 @@ parser = Lark(r'''
| concat_func "~" -> reverse
| concat_func "~" NUMBER -> roll
| concat_func "~{" NUMBER ["," DIGITS] "}" -> roll
| concat_func "!" -> collapse
| concat_func "!" DIGIT+ -> collapse
| concat_func "!{" numrange ("," numrange)* "}" -> collapse_ranges
| concat_func "\\" DIGIT+ -> index
| concat_func "\\{" numrange ("," numrange)* "}" -> index_ranges
@ -144,6 +146,23 @@ class Expand(Transformer):
result.append(x[i % len(x)])
return result
def collapse(self, args):
result, x = '', args[0]
if len(args) > 1:
for i in args[1:]:
result += x[int(i.value) % len(x)]
else:
result = ''.join(args[0])
return [result]
def collapse_ranges(self, args):
result, x = '', args[0]
for arg in args[1:]:
for i in arg:
result += x[i % len(x)]
return [result]
def concat_repeat(self, args):
return self.concat([args[0]] * int(args[1].value))
def either_repeat(self, args):