Compare commits

..

No commits in common. "a5737d9afb74357e8cb3ac2efed3802913d2481c" and "1150453fd73ac615de31d4494570b0bb027d0ae1" have entirely different histories.

12 changed files with 39 additions and 53 deletions

View File

@ -11,9 +11,9 @@ release:
test:
crystal spec
deps:
shards install --ignore-crystal-version
shards install
deps_update:
shards update --ignore-crystal-version
shards update
deps_opt:
@[ -d lib/ ] || make deps
doc:

View File

@ -1,6 +1,6 @@
# DashBot
A good bot, or a collection of plugins for Crirc network client.
TODO: Write a description here
## Installation
@ -40,7 +40,7 @@ TODO: Write development instructions here
## Contributing
1. Fork it ( https://git.sceptique.eu/Sceptique/DashBot/fork )
1. Fork it ( https://github.com/Meoowww/DashBot/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
@ -48,5 +48,5 @@ TODO: Write development instructions here
## Contributors
- [Sceptique](https://git.sceptique.eu/Sceptique) Arthur Poulet - creator, maintainer
- [pouleta](https://github.com/Nephos) Arthur Poulet - creator, maintainer
- [Lucie](https://github.com/Lucie-Dispot) Lucie Dispot - developer

View File

@ -1,8 +1,12 @@
version: 2.0
shards:
crirc:
git: https://git.sceptique.eu/Sceptique/Crirc
version: 0.5.1+git.commit.1aab6b69c7e9cca6780bc335d7b79739e201f1dd
git: https://github.com/meoowww/crirc.git
version: 0.5.1+git.commit.c21010a9d9d3ef9067b5610ec4cb4ea389fdc508
daemonize:
git: https://github.com/dougeverly/daemonize.cr.git
version: 0.1.0+git.commit.03d7da27fe76ee6b77d47a66984969a308a42027
db:
git: https://github.com/crystal-lang/crystal-db.git
@ -10,7 +14,7 @@ shards:
dotenv:
git: https://github.com/gdotdesign/cr-dotenv.git
version: 1.0.0
version: 0.7.0
micrate:
git: https://github.com/juanedi/micrate.git
@ -25,8 +29,8 @@ shards:
version: 0.23.1
rollable:
git: https://git.sceptique.eu/Sceptique/rollable
version: 1.0.0+git.commit.84ef972fec468d03381a815675b7a906b792458b
git: https://github.com/nephos/crystal_rollable.git
version: 1.0.0+git.commit.050af10ac2076293e79c69b511d1f3e0e0835f86
sqlite3:
git: https://github.com/crystal-lang/crystal-sqlite3.git

View File

@ -11,11 +11,11 @@ crystal: 1.0.0
dependencies:
# irc
crirc:
git: https://git.sceptique.eu/Sceptique/Crirc
github: Meoowww/Crirc
branch: master
# dice roll
rollable:
git: https://git.sceptique.eu/Sceptique/rollable
github: Nephos/crystal_rollable
branch: master
# Sql
pg:

View File

@ -44,8 +44,7 @@ module DashBot
Plugins::Reminder.bind(bot)
Plugins::Rpg.bind(bot)
Plugins::Random.bind(bot)
Plugins::Anarchism.bind(bot)
Plugins::TitleReader.bind(bot)
# Plugins::Anarchism.bind(bot)
bot.on_ready do
bot.join (ARGV.empty? ? ["#equilibre"] : ARGV).map { |chan| Crirc::Protocol::Chan.new(chan) }

View File

@ -16,7 +16,7 @@ module DashBot::Plugins::Messages
id = match.as(Regex::MatchData)[1]
message = match.as(Regex::MatchData)[2]
DB.exec "INSERT INTO messages (author, dest, content, created_at)
VALUES ($1, $2, $3, NOW())", msg.source.source_id, id, message
VALUES ($1, $2, $3, NOW())", [msg.source.source_id, id, message]
# bot.privmsg User.new(msg.source.source_id), "Message sent to \"#{id}\""
bot.reply msg, "Message sent to \"#{id}\""
end
@ -26,7 +26,7 @@ module DashBot::Plugins::Messages
bot.on("PRIVMSG", message: /^!read$/, doc: {"!read", "!read read the inbox"}) do |msg, match|
m = DB.query_one(
"SELECT id, author, dest, content, created_at, read_at FROM messages WHERE read_at IS NULL AND dest = $1
ORDER BY created_at ASC LIMIT 1", msg.source.source_id, as: {Int32, String, String, String, Time, Time?}) rescue nil
ORDER BY created_at ASC LIMIT 1", [msg.source.source_id], as: {Int32, String, String, String, Time, Time?}) rescue nil
if m
message = {id: m[0], author: m[1], dest: m[2], content: m[3], created_at: m[4], read_at: m[5]}
# user = User.new(msg.source.source_id)
@ -46,7 +46,7 @@ module DashBot::Plugins::Messages
def bind_signal(bot)
bot.on("JOIN") do |msg, _|
count = DB.query_one("SELECT COUNT(*) FROM messages WHERE read_at IS NULL and DEST = $1", msg.source.source_id, as: {Int64})
count = DB.query_one("SELECT COUNT(*) FROM messages WHERE read_at IS NULL and DEST = $1", [msg.source.source_id], as: {Int64})
bot.reply msg, "#{msg.source.source_id}, you have #{count} messages" if count > 0
end
end

View File

@ -24,7 +24,7 @@ module DashBot::Plugins::Reminder
bot.on("PRIVMSG", message: /^!remindme$/, doc: {"!remindme", "!remindme"}) do |msg, match|
messages = DB.query_all(
"SELECT id, author, remind_time, content, created_at, checked_at, read_at FROM reminders WHERE read_at IS NULL AND author = $1",
msg.source.source_id, as: {Int32, String, Time, String, Time, Time?, Time?}) rescue nil
[msg.source.source_id], as: {Int32, String, Time, String, Time, Time?, Time?}) rescue nil
if messages
messages.each do |m|
message = {id: m[0], author: m[1], remind_time: m[2], content: m[3], created_at: m[4], read_at: m[5]}
@ -64,7 +64,7 @@ module DashBot::Plugins::Reminder
def bind_signal(bot)
bot.on("JOIN") do |msg, _|
count = DB.query_one("SELECT COUNT(*) FROM reminders WHERE read_at IS NULL and checked_at IS NOT NULL and author = $1", msg.source.source_id, as: {Int64})
count = DB.query_one("SELECT COUNT(*) FROM reminders WHERE read_at IS NULL and checked_at IS NOT NULL and author = $1", [msg.source.source_id], as: {Int64})
bot.reply msg, "#{msg.source.source_id}, you have #{count} reminders" if count > 0
end
end

View File

@ -13,7 +13,7 @@ module DashBot::Plugins::Rpg::Music
bot.on("PRIVMSG", message: /^!music +add +([[:graph:]]+) +([[:graph:]]+)/) do |msg, match|
msg_match = match.as Regex::MatchData
DB.exec("INSERT INTO musics (owner, category, url, created_at)
VALUES ($1, $2, $3, NOW())", msg.source.source_id, msg_match[1], msg_match[2])
VALUES ($1, $2, $3, NOW())", [msg.source.source_id, msg_match[1], msg_match[2]])
bot.reply msg, "Music successfully added."
end
end
@ -21,12 +21,12 @@ module DashBot::Plugins::Rpg::Music
def bind_del_music(bot)
bot.on("PRIVMSG", message: /^!music +delete +([[:graph:]]+) +([[:graph:]]+)/) do |msg, match|
msg_match = match.as Regex::MatchData
musics = DB.query_all("SELECT url FROM musics WHERE category = $1", msg_match[1], as: {String})
musics = DB.query_all("SELECT url FROM musics WHERE category = $1", [msg_match[1]], as: {String})
if msg_match[2].to_i > musics.size
bot.reply msg, "This music doesn't exist."
else
DB.exec("DELETE FROM musics WHERE url = $1", musics[msg_match[2].to_i - 1]["url"])
DB.exec("DELETE FROM musics WHERE url = $1", [musics[msg_match[2].to_i - 1]["url"]])
bot.reply msg, "Music successfully deleted."
end
end
@ -41,7 +41,7 @@ module DashBot::Plugins::Rpg::Music
bot.on("PRIVMSG", message: /^!music +(?:list|ls) +([[:graph:]]+)/) do |msg, match|
msg_match = match.as Regex::MatchData
urls = DB.query_all("SELECT url FROM musics WHERE category = $1 LIMIT 5", msg_match[1], as: {String}).join(", ")
urls = DB.query_all("SELECT url FROM musics WHERE category = $1 LIMIT 5", [msg_match[1]], as: {String}).join(", ")
bot.reply msg, "The following musics are present in the category #{msg_match[1]}: #{urls}"
end
end
@ -50,14 +50,14 @@ module DashBot::Plugins::Rpg::Music
# Select a random music
bot.on("PRIVMSG", message: /^!music play +([[:graph:]]+) +$/) do |msg, match|
msg_match = match.as Regex::MatchData
musics = DB.query_all("SELECT url FROM musics WHERE category = $1", msg_match[1], as: {String})
musics = DB.query_all("SELECT url FROM musics WHERE category = $1", [msg_match[1]], as: {String})
bot.reply msg, "#{musics.sample}"
end
# Select a specific music
bot.on("PRIVMSG", message: /^!music play +([[:graph:]]+) +([[:graph:]]+)/) do |msg, match|
msg_match = match.as Regex::MatchData
musics = DB.query_all("SELECT url FROM musics WHERE category = $1", msg_match[1], as: {String})
musics = DB.query_all("SELECT url FROM musics WHERE category = $1", [msg_match[1]], as: {String})
if msg_match[2].to_i > musics.size
bot.reply msg, "Error: this track doesn't exist (yet)."
else

View File

@ -25,7 +25,7 @@ module DashBot::Plugins::Rpg::Roll
# check if name already exists
n = DB.query_one("SELECT COUNT(*) FROM dies WHERE name = $1 AND owner = $2",
msg_match[1], msg.source.source_id, as: {Int64})
[msg_match[1], msg.source.source_id], as: {Int64})
if n > 0
bot.reply msg, "Error: #{msg_match[1]} already exists. Remove it or use another name."
@ -44,7 +44,7 @@ module DashBot::Plugins::Rpg::Roll
msg_match = match.as Regex::MatchData
begin
roll = DB.query_one("SELECT roll FROM dies WHERE name = $1 AND owner = $2",
msg_match[1], msg.source.source_id, as: {String})
[msg_match[1], msg.source.source_id], as: {String})
rescue
bot.reply msg, "Roll #{msg_match[1]} does not exist."
next
@ -62,7 +62,7 @@ module DashBot::Plugins::Rpg::Roll
match = match.as Regex::MatchData
limit = (match[2]? || "8").to_i
all_rolls = DB.query_all("SELECT owner, roll FROM dies WHERE name = $1",
match[1], as: {String, String})
[match[1]], as: {String, String})
rolls = all_rolls.shift(limit)
bot.reply msg, "#{all_rolls.size} rolls will not be launch." if !all_rolls.empty?

View File

@ -1,17 +0,0 @@
require "http/client"
require "xml"
module DashBot::Plugins::TitleReader
extend self
def bind(bot)
bot.on("PRIVMSG", message: /(http[^ ]+)/, doc: {"any url", "look a this http://url/"}) do |msg, match|
match = match.as Regex::MatchData
url = match[1]
response = HTTP::Client.get url
xml = XML.parse response.body
title_node = xml.xpath_node("//title")
bot.reply msg, "(#{title_node.text})" if title_node
end
end
end

View File

@ -20,9 +20,9 @@ module DashBot::Plugins::UserCommands
match = match.as Regex::MatchData
if user_exists? match[1]
groups = DB.query_all("SELECT groups.id AS id, groups.name AS name FROM groups
INNER JOIN users ON groups.user_name = users.name WHERE users.name = $1", match[1], as: {Int32, String})
INNER JOIN users ON groups.user_name = users.name WHERE users.name = $1", [match[1]], as: {Int32, String})
if idx = groups.index { |e| e[1] == match[2] }
DB.exec "DELETE FROM groups WHERE id = $1", groups[idx][0]
DB.exec "DELETE FROM groups WHERE id = $1", [groups[idx][0]]
bot.reply msg, "The user \"#{match[1]}\" has lost the group \"#{match[2]}\""
else
bot.reply msg, "The user \"#{match[1]}\" does not belongs to the group \"#{match[2]}\""
@ -38,7 +38,7 @@ module DashBot::Plugins::UserCommands
match = match.as Regex::MatchData
if user_exists? match[1]
groups = DB.query_all("SELECT groups.name AS name FROM groups
INNER JOIN users ON groups.user_name = users.name WHERE users.name = $1", match[1], as: {String})
INNER JOIN users ON groups.user_name = users.name WHERE users.name = $1", [match[1]], as: {String})
groups = groups.join(", ")
bot.reply msg, "User \"#{match[1]}\" has the groups : #{groups}"
else
@ -52,7 +52,7 @@ module DashBot::Plugins::UserCommands
next if !authorize! bot, msg
match = match.as Regex::MatchData
if user_exists? match[1]
DB.exec "INSERT INTO groups (user_name, name) VALUES ($1, $2)", match[1], match[2]
DB.exec "INSERT INTO groups (user_name, name) VALUES ($1, $2)", [match[1], match[2]]
bot.reply msg, "The user \"#{match[1]}\" has gained the group \"#{match[2]}\""
else
bot.reply msg, "User \"#{match[1]}\" not registered"
@ -66,9 +66,9 @@ module DashBot::Plugins::UserCommands
bot.reply msg, "Cannot register \"#{msg.source.source_id}\" twice"
else
bot.reply msg, "Register \"#{msg.source.source_id}\""
is_admin = DB.query_one("SELECT COUNT(*) FROM users", as: {Int64}) == 0
DB.exec "INSERT INTO users (name) VALUES ($1)", msg.source.source_id
DB.exec "INSERT INTO groups (user_name, name) VALUES ($1, $2)", msg.source.source_id, is_admin ? "admin" : "default"
is_admin = DB.query_one("SELECT COUNT(*) FROM users", [] of Int64, as: {Int64}) == 0
DB.exec "INSERT INTO users (name) VALUES ($1)", [msg.source.source_id]
DB.exec "INSERT INTO groups (user_name, name) VALUES ($1, $2)", [msg.source.source_id, is_admin ? "admin" : "default"]
end
end
end

View File

@ -3,7 +3,7 @@ module DashBot
def authorized?(msg, group = "admin")
n = DB.query_one("SELECT COUNT(*) FROM groups
INNER JOIN users ON groups.user_name = users.name WHERE groups.name = $1 AND users.name = $2",
group, msg.source.source_id, as: {Int64})
[group, msg.source.source_id], as: {Int64})
n == 1
end