Initial commit

This commit is contained in:
Sebastian Korotkiewicz 2022-04-02 19:52:55 +02:00
commit 265f229824
Signed by: grizzly
GPG Key ID: 5BDC557B496BDB0D
10 changed files with 1151 additions and 0 deletions

18
.eslintrc.json Normal file
View File

@ -0,0 +1,18 @@
{
"rules": {
"no-unused-vars": "warn",
"no-console": "warn",
"no-empty": "off",
"no-warning-comments": [
"warn",
{ "terms": ["fixme", "xxx", "todo"], "location": "anywhere" }
]
},
"parserOptions": {
"ecmaVersion": 2017
},
"sourceType": "module",
"env": {
"es6": true
}
}

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
irclogs/*.log

12
README.md Normal file
View File

@ -0,0 +1,12 @@
# irc_log
my tiny irc bot in nodejs for save logs in irssi format for pisg
## install
```bash
$ git clone https://tildegit.org/grizzly/irc_log.git
$ yarn install
$ nano index.js
$ yarn start
```

8
Save.js Normal file
View File

@ -0,0 +1,8 @@
import { appendFile } from "fs";
const Save = (target, message) => {
target = target.replace("#", "");
return appendFile(`irclogs/c-${target}.log`, `${message} \n`, () => {});
};
export default Save;

8
crontab Normal file
View File

@ -0,0 +1,8 @@
#minute (0-59),
#| hour (0-23),
#| | day of the month (1-31),
#| | | month of the year (1-12),
#| | | | day of the week (0-6 with 0=Sunday).
#| | | | | commands
0 0 * * * /home/grizzly/irc/pisg/pisg --silent ; mv /home/grizzly/team.html "/home/grizzly/public_html/irc/`date +"%F"`-team.html" ; mv /home/grizzly/meta.html "/home/grizzly/public_html/irc/`date +"%F"`-meta.html" ; rm /home/grizzly/irc/irc_log/irclogs/*.log

45
index.js Normal file
View File

@ -0,0 +1,45 @@
import { Client } from "irc-framework";
import Save from "./Save.js";
function middleware() {
return function (client, raw_events, parsed_events) {
parsed_events.use(log);
};
function log(command, event, client, next) {
const formatTime = (i) => {
return (i = i < 10 ? "0" + i : i);
};
const time = new Date();
let h = formatTime(time.getHours());
let m = formatTime(time.getMinutes());
if (command === "message") {
if (event.nick)
Save(event.target, `${h}:${m} < ${event.nick}> ${event.message}`);
}
next();
}
}
const bot = new Client();
bot.use(middleware());
bot.connect({
host: "localhost",
nick: "g-itz",
port: 6667,
version: "g-itz",
username: "g-itz",
gecos: "g-itz",
});
bot.on("registered", () => {
console.log("Connected!");
bot.join("#grizzly");
bot.join("#grizzly2");
});
bot.on("close", () => {
console.log("Connection close");
});

0
irclogs/.gitkeep Normal file
View File

16
package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "irc_bot",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"irc-framework": "^4.12.1"
},
"type": "module",
"devDependencies": {
"eslint": "^8.12.0"
}
}

41
user-systemd/irc_log.md Normal file
View File

@ -0,0 +1,41 @@
## Create a systemd service unit file under the directory.
```
$ vim ~/.config/systemd/user/irc_log.service
[Unit]
Description=irc_log
After=network.target
[Service]
ExecStart=/usr/bin/node /home/grizzly/irc/irc_log/index.js
WorkingDirectory=%h/irc/irc_log
Restart=always
[Install]
WantedBy=multi-user.target
```
## Reload systemd.
```
$ systemctl --user daemon-reload
```
## Confirm the service is available.
```
$ systemctl --user list-unit-files irc_log.service
```
## You can start the service then after creation.
```
$ systemctl --user enable --now irc_log.service
```
## Lets check the status of our service.
```
$ systemctl --user status irc_log.service
```

1001
yarn.lock Normal file

File diff suppressed because it is too large Load Diff