Skip to content
Snippets Groups Projects
Verified Commit 727c0c95 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Added readme, improved queries

parent f79007aa
No related branches found
No related tags found
No related merge requests found
# KStats
## Setup
1. Create a PostgreSQL user and database for the statsbot
2. Apply the schema (see `schema.sql` to the database)
3. Add channels to the channels table
4. Start the bot
## Configuration
The bot takes several environment variables for configuration.
Required variables are marked with *
| Name | Example | Description |
| ------------------------ | ---------------------------------------------- | ------------------------------------------------------ |
|`KSTATS_IRC_SERVER`* | `irc.rizon.net` | Irc Servername |
|`KSTATS_IRC_PORT`* | `6697` | Irc Port |
|`KSTATS_IRC_SECURE` | `true` | If TLS should be enabled for this connection |
|`KSTATS_IRC_NICK` |`kstats` | Nickname visible on IRC |
|`KSTATS_IRC_IDENT` |`kstats` | Ident visible on IRC |
|`KSTATS_IRC_REALNAME` |`KStats kuschku.de Statistics Bot` | Realname visible on IRC |
|`KSTATS_IRC_SASL_ENABLED` |`true` | If SASL is enabled |
|`KSTATS_IRC_SASL_ACCOUNT` |`kstats` | SASL Username |
|`KSTATS_IRC_SASL_PASSWORD`|`caa5db269fc39` | SASL Password |
|`KSTATS_DATABASE_TYPE`* |`postgres` | Database driver (only postgres is supported currently) |
|`KSTATS_DATABASE_URL`* |`postgresql://kstats:hunter2@localhost/statsbot`| Database URL |
......@@ -212,9 +212,8 @@ func handlePrivateMessage(channels map[string]IrcChannel, event girc.Event, clie
if len(parameters) == 1 {
channelName := parameters[0]
if channelData, ok := channels[channelName]; ok {
nick := event.Source.Name
hash := hashName(channelData.Salt, nick)
_, err := db.Exec("DELETE FROM users WHERE hash = $1 AND nick = $2", hash, nick)
hash := hashName(channelData.Salt, event.Source.Name)
_, err := db.Exec("DELETE FROM users WHERE hash = $1", hash)
if err != nil {
client.Cmd.Reply(event, "An error has occured, please try later again")
println(err.Error())
......@@ -260,7 +259,7 @@ func logMessage(channelData IrcChannel, event girc.Event, client *girc.Client, c
}
}
for _, user := range users {
_, err := db.Exec("INSERT INTO \"references\" (time, source, target) VALUES ($1, $2, $3)", now, name, user)
_, err := db.Exec("INSERT INTO \"references\" (channel, time, source, target) VALUES ($1, $2, $3, $4)", channelData.Id, now, name, user)
if err != nil {
println(err.Error())
}
......
create table messages (
id serial not null
constraint messages_pkey primary key,
time timestamp,
channel integer
constraint messages_channels_id_fk references channels on update cascade on delete cascade,
sender text,
words integer,
characters integer,
question boolean,
exclamation boolean,
caps boolean,
aggression boolean,
emoji_happy boolean,
emoji_sad boolean
);
create index messages_channel_index
on messages (channel);
create index messages_channel_sender_index
on messages (channel, sender);
create table users (
hash text not null
constraint users_pkey primary key,
nick text
);
create table "references" (
id serial not null
constraint references_pkey primary key,
channel integer
constraint references_channels_id_fk references channels on update cascade on delete cascade,
time timestamp,
source text,
target text
);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment