Skip to content

Commit

Permalink
Add !help
Browse files Browse the repository at this point in the history
  • Loading branch information
Nephos committed Nov 29, 2017
1 parent d5b5932 commit 493f76b
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 1.0
shards:
crirc:
github: Meoowww/Crirc
commit: 4fd50613f425628ba2bfdaf25f3868fb731cb54e
commit: e67bf5a095723a3ed34d1f79153c7fcdb7df8e9a

daemonize:
github: DougEverly/daemonize.cr
Expand Down
2 changes: 1 addition & 1 deletion src/DashBot.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
module DashBot
def start
Arguments.new.use
client = Crirc::Network::Client.new(ip: "irc.mozilla.org", port: 6667_u16, ssl: false, nick: "Dasshyxtest", read_timeout: 300_u16)
client = Crirc::Network::Client.new(ip: "irc.mozilla.org", port: 6667_u16, ssl: false, nick: "Dasshyxtest2", read_timeout: 300_u16)
client.connect
client.start do |bot|
Plugins::BasicCommands.bind(bot)
Expand Down
6 changes: 3 additions & 3 deletions src/DashBot/plugins/admin_commands.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module DashBot::Plugins::AdminCommands
include Rights

def bind(bot)
bot.on("PRIVMSG", message: /^!kick +([[:graph:]]+)(?: (.+))?/) do |msg, match|
bot.on("PRIVMSG", message: /^!kick +([[:graph:]]+)(?: (.+))?/, doc: {"!kick", "!kick user"}) do |msg, match|
next if !authorize! bot, msg, %w(admin modo), "You cannot kick, you are not an \"admin\" nor a \"modo\""
chan = Crirc::Protocol::Chan.new msg.argument_list.first
user = Crirc::Protocol::User.new match.as(Regex::MatchData)[1]
bot.kick([chan], [user], match.as(Regex::MatchData)[2]?)
end.on("PRIVMSG", message: /^!(join|part) +([[:graph:]]+)/) do |msg, match|
end.on("PRIVMSG", message: /^!(join|part) +([[:graph:]]+)/, doc: {"!join", "!join/part #chan"}) do |msg, match|
match = match.as(Regex::MatchData)
command = match[1]
next if !authorize! bot, msg, "admin", "You cannot #{command}, you are not an \"admin\""
chan = Crirc::Protocol::Chan.new match[2]
bot.join([chan]) if command == "join"
bot.part([chan]) if command == "part"
end.on("PRIVMSG", message: /^!privmsg +([[:graph:]]+) +(.+)/) do |msg, match|
end.on("PRIVMSG", message: /^!privmsg +([[:graph:]]+) +(.+)/, doc: {"!privmsg", "!privmsg user message"}) do |msg, match|
match = match.as(Regex::MatchData)
command = match[1]
next if !authorize! bot, msg, "admin", "You cannot #{command}, you are not an \"admin\""
Expand Down
11 changes: 8 additions & 3 deletions src/DashBot/plugins/basic_commands.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ module DashBot::Plugins::BasicCommands
end.on("PING") do |msg|
STDERR.puts "[#{Time.now}] PONG :#{msg.message}"
bot.pong(msg.message)
end.on("PRIVMSG", message: /^!ping/) do |msg|
end.on("PRIVMSG", message: /^!ping/, doc: {"!ping", "!ping"}) do |msg|
bot.reply msg, "pong #{msg.source.source_id}"
end.on("PRIVMSG", message: /^!roll +([^:]+)( *: *(.+))?/) do |msg, match|
end.on("PRIVMSG", message: /^!roll +([^:]+)( *: *(.+))?/, doc: {"!roll", "!roll dice : msg"}) do |msg, match|
match = match.as Regex::MatchData
r = Rollable::Roll.parse(match[1]).compact!.order!
result = r.test_details
bot.reply msg, "#{msg.source.source_id}: [#{match[3]?}] #{result.sum} (#{r.to_s} = #{result.join(", ")})"
end.on("PRIVMSG", message: /^!call +(.+)/) do |msg, match|
end.on("PRIVMSG", message: /^!call +(.+)/, doc: {"!call", "!call someone"}) do |msg, match|
match = match.as Regex::MatchData
bot.reply msg, "I'm calling #{match[1]} right now"
end.on("PRIVMSG", message: /(^| )what($| )/i) do |msg, match|
Expand All @@ -29,6 +29,11 @@ module DashBot::Plugins::BasicCommands
bot.reply msg, "AH"
end.on("PRIVMSG", message: /^oulah/i) do |msg, match|
bot.reply msg, "Vous êtes con"
end.on(message: /^!help *$/, doc: {"!help", "!help to list the modules\n!help cmd display the description of the cmd"}) do |msg|
bot.reply msg, bot.docs.keys.join(", ")
end.on(message: /^!help *(.*[^ ]) *$/) do |msg, match|
doc = bot.docs[match.as(Regex::MatchData)[1]]?
doc.split("\n").each { |split| bot.reply msg, "- #{split}" } unless doc.nil?
end
end
end
4 changes: 2 additions & 2 deletions src/DashBot/plugins/messages.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module DashBot::Plugins::Messages
end

def bind_write(bot)
bot.on("PRIVMSG", message: /^!write +(\w+) +(.+)$/) do |msg, match|
bot.on("PRIVMSG", message: /^!write +(\w+) +(.+)$/, doc: {"!write", "!write someone message"}) do |msg, match|
id = match.as(Regex::MatchData)[1]
message = match.as(Regex::MatchData)[2]
DB.exec "INSERT INTO messages (author, dest, content, created_at)
Expand All @@ -23,7 +23,7 @@ module DashBot::Plugins::Messages
end

def bind_read(bot)
bot.on("PRIVMSG", message: /^!read$/) do |msg, match|
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
Expand Down
6 changes: 3 additions & 3 deletions src/DashBot/plugins/points.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module DashBot::Plugins::Points
end

def bind_add(bot)
bot.on("PRIVMSG", message: /^!p +([[:graph:]]+) +([[:graph:]]+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!p +([[:graph:]]+) +([[:graph:]]+)/, doc: {"!p", "!p type someone"}) do |msg, match|
match = match.as Regex::MatchData
DB.exec "INSERT INTO points (assigned_to, assigned_by, type, created_at)
VALUES ($1, $2, $3, NOW())", [match[2], msg.source.source_id, match[1].downcase]
Expand All @@ -19,12 +19,12 @@ module DashBot::Plugins::Points
end

def bind_list(bot)
bot.on("PRIVMSG", message: /^!pl +([[:graph:]]+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!pl +([[:graph:]]+)/, doc: {"!pl", "!pl type list winners of the category"}) do |msg, match|
match = match.as Regex::MatchData
points = DB.query_all("SELECT assigned_to, COUNT(*) FROM points WHERE type = $1 GROUP BY assigned_to ORDER BY COUNT(*) DESC LIMIT 5;", [match[1]], as: {String, Int64})
bot.reply msg, "#{match[1]}: " + points.map { |point| "#{point[0]}: #{point[1]}" }.join(", ")
end
bot.on("PRIVMSG", message: /^!plu +([[:graph:]]+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!plu +([[:graph:]]+)/, doc: {"!plu", "!plu user list the best categories of the user"}) do |msg, match|
match = match.as Regex::MatchData
points = DB.query_all("SELECT type, COUNT(*) FROM points WHERE assigned_to = $1 GROUP BY type ORDER BY COUNT(*) DESC LIMIT 5;", [match[1]], as: {String, Int64})
bot.reply msg, "#{match[1]}: " + points.map { |point| "#{point[0]}: #{point[1]}" }.join(", ")
Expand Down
2 changes: 1 addition & 1 deletion src/DashBot/plugins/random.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DashBot::Plugins::Random
extend self

def bind(bot)
bot.on("PRIVMSG", message: /^!random +([[:alnum:]]+(, ?[[:alnum:]]+))+/) do |msg, match|
bot.on("PRIVMSG", message: /^!random +([[:alnum:]]+(, ?[[:alnum:]]+))+/, doc: {"!random", "!random word1,word2,word3"}) do |msg, match|
match = match.as(Regex::MatchData)
list = match[1]
values = list.split(/(, )|([^,] )/)
Expand Down
4 changes: 2 additions & 2 deletions src/DashBot/plugins/reminder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module DashBot::Plugins::Reminder
end

def bind_write(bot)
bot.on("PRIVMSG", message: /^!reminder +([[:graph:]]+) +(.+)$/) do |msg, match|
bot.on("PRIVMSG", message: /^!reminder +([[:graph:]]+) +(.+)$/, doc: {"!reminder", "!reminder d/m/y message"}) do |msg, match|
dest_time = Time.adaptive_parse(match.as(Regex::MatchData)[1])
message = match.as(Regex::MatchData)[2]
DB.exec "INSERT INTO reminders (author, remind_time, content, created_at)
Expand All @@ -21,7 +21,7 @@ module DashBot::Plugins::Reminder
end

def bind_read(bot)
bot.on("PRIVMSG", message: /^!remindme$/) do |msg, match|
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
Expand Down
8 changes: 4 additions & 4 deletions src/DashBot/plugins/user_commands.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module DashBot::Plugins::UserCommands
end

def bind_group_rm(bot)
bot.on("PRIVMSG", message: /^!group +rm +(\w+) +(\w+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!group +rm +(\w+) +(\w+)/, doc: {"!group rm", "!group rm user group"}) do |msg, match|
next if !authorize! bot, msg
match = match.as Regex::MatchData
if user_exists? match[1]
Expand All @@ -34,7 +34,7 @@ module DashBot::Plugins::UserCommands
end

def bind_group_ls(bot)
bot.on("PRIVMSG", message: /^!group +(?:list|ls) (\w+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!group +(?:list|ls) (\w+)/, doc: {"!group ls", "!group ls user"}) do |msg, match|
match = match.as Regex::MatchData
if user_exists? match[1]
groups = DB.query_all("SELECT groups.name AS name FROM groups
Expand All @@ -48,7 +48,7 @@ module DashBot::Plugins::UserCommands
end

def bind_group_add(bot)
bot.on("PRIVMSG", message: /^!group +add +(\w+) +(\w+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!group +add +(\w+) +(\w+)/, doc: {"!group add", "!group add user group"}) do |msg, match|
next if !authorize! bot, msg
match = match.as Regex::MatchData
if user_exists? match[1]
Expand All @@ -61,7 +61,7 @@ module DashBot::Plugins::UserCommands
end

def bind_register(bot)
bot.on("PRIVMSG", message: /^!register/) do |msg|
bot.on("PRIVMSG", message: /^!register/, doc: {"!register", "!register"}) do |msg|
if user_exists? msg.source.source_id
bot.reply msg, "Cannot register \"#{msg.source.source_id}\" twice"
else
Expand Down

0 comments on commit 493f76b

Please sign in to comment.