Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
statsbot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Janne Mareike Koschinski
statsbot
Commits
727c0c95
Verified
Commit
727c0c95
authored
6 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Added readme, improved queries
parent
f79007aa
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Readme.md
+27
-0
27 additions, 0 deletions
Readme.md
main.go
+3
-4
3 additions, 4 deletions
main.go
schema.sql
+37
-0
37 additions, 0 deletions
schema.sql
with
67 additions
and
4 deletions
Readme.md
0 → 100644
+
27
−
0
View file @
727c0c95
# 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 |
This diff is collapsed.
Click to expand it.
main.go
+
3
−
4
View file @
727c0c95
...
...
@@ -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
())
}
...
...
This diff is collapsed.
Click to expand it.
schema.sql
0 → 100644
+
37
−
0
View file @
727c0c95
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment