Skip to content

Commit

Permalink
Fix stupid parsing error
Browse files Browse the repository at this point in the history
spaces were not required in lots of regex
  • Loading branch information
Nephos committed Oct 3, 2017
1 parent 5ce8644 commit e0bd068
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
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:]]+)(?: (.+))?/) do |msg, match|
next if !authorize! msg, %w(admin modo), "You cannot kick, you are not an \"admin\" nor a \"modo\""
chan = CrystalIrc::Chan.new msg.arguments.first
user = CrystalIrc::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:]]+)/) do |msg, match|
match = match.as(Regex::MatchData)
command = match[1]
next if !authorize! msg, "admin", "You cannot #{command}, you are not an \"admin\""
chan = CrystalIrc::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:]]+) +(.+)/) do |msg, match|
match = match.as(Regex::MatchData)
command = match[1]
next if !authorize! msg, "admin", "You cannot #{command}, you are not an \"admin\""
Expand Down
4 changes: 2 additions & 2 deletions src/DashBot/plugins/basic_commands.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module DashBot::Plugins::BasicCommands
bot.pong(msg.message)
end.on("PRIVMSG", message: /^!ping/) do |msg|
msg.reply "pong #{msg.hl}"
end.on("PRIVMSG", message: /^!roll *([^:]+)( *: *(.+))?/) do |msg, match|
end.on("PRIVMSG", message: /^!roll +([^:]+)( +: +(.+))?/) do |msg, match|
match = match.as Regex::MatchData
r = Rollable::Roll.parse(match[1]).compact!.order!
result = r.test_details
msg.reply "#{msg.hl}: [#{match[3]?}] #{result.sum} (#{r.to_s} = #{result.join(", ")})"
end.on("PRIVMSG", message: /^!call *(.+)/) do |msg, match|
end.on("PRIVMSG", message: /^!call +(.+)/) do |msg, match|
match = match.as Regex::MatchData
msg.reply "I'm calling #{match[1]} right now"
end.on("PRIVMSG", message: /(^| )what($| )/i) do |msg, match|
Expand Down
2 changes: 1 addition & 1 deletion 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+) +(.+)$/) 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 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:]]+)/) 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_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:]]+)/) 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})
msg.reply "#{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:]]+)/) 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})
msg.reply "#{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:]]+))+/) do |msg, match|
match = match.as(Regex::MatchData)
list = match[1]
values = list.split(/(, )|([^,] )/)
Expand Down
2 changes: 1 addition & 1 deletion src/DashBot/plugins/reminder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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:]]+) +(.+)$/) 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 Down
12 changes: 6 additions & 6 deletions src/DashBot/plugins/rpg/music.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module DashBot::Plugins::Rpg::Music
end

def bind_add_music(bot)
bot.on("PRIVMSG", message: /^!music add ([[:graph:]]+) ([[:graph:]]+)/) do |msg, match|
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_id, msg_match[1], msg_match[2]])
Expand All @@ -19,7 +19,7 @@ module DashBot::Plugins::Rpg::Music
end

def bind_del_music(bot)
bot.on("PRIVMSG", message: /^!music delete ([[:graph:]]+) ([[:graph:]]+)/) do |msg, match|
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})

Expand All @@ -33,13 +33,13 @@ module DashBot::Plugins::Rpg::Music
end

def bind_list_music(bot)
bot.on("PRIVMSG", message: /^!music (?:list|ls) *$/) do |msg|
bot.on("PRIVMSG", message: /^!music +(?:list|ls) +$/) do |msg|
# Do not trigger if the user was asking for a specific category
categories = DB.query_all("SELECT DISTINCT category FROM musics", as: {String}).join(", ")
msg.reply "The following music categories exist: #{categories}"
end

bot.on("PRIVMSG", message: /^!music (?:list|ls) ([[:graph:]]+)/) do |msg, match|
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(", ")
msg.reply "The following musics are present in the category #{msg_match[1]}: #{urls}"
Expand All @@ -48,14 +48,14 @@ module DashBot::Plugins::Rpg::Music

def bind_link_music(bot)
# Select a random music
bot.on("PRIVMSG", message: /^!music play ([[:graph:]]+) *$/) do |msg, match|
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})
msg.reply "#{musics.sample}"
end

# Select a specific music
bot.on("PRIVMSG", message: /^!music play ([[:graph:]]+) ([[:graph:]]+)/) do |msg, match|
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})
if msg_match[2].to_i > musics.size
Expand Down
12 changes: 6 additions & 6 deletions src/DashBot/plugins/rpg/roll.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module DashBot::Plugins::Rpg::Roll

# !rroll NAME DICE = prepare a new dice named NAME
def bind_add_roll(bot)
bot.on("PRIVMSG", message: /^!rroll ([[:graph:]]+) ([[:graph:]]+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!rroll +([[:graph:]]+) +([[:graph:]]+)/) do |msg, match|
msg_match = match.as Regex::MatchData

# Check for roll correctness
Expand All @@ -39,7 +39,7 @@ module DashBot::Plugins::Rpg::Roll

# !rrol NAME = roll the dice named NAME
def bind_launch_roll(bot)
bot.on("PRIVMSG", message: /^!rroll ([[:graph:]]+) *$/) do |msg, match|
bot.on("PRIVMSG", message: /^!rroll +([[:graph:]]+) +$/) do |msg, match|
# Do not trigger if the user was registering a roll
msg_match = match.as Regex::MatchData
begin
Expand All @@ -58,7 +58,7 @@ module DashBot::Plugins::Rpg::Roll

# !groll NAME MAX = roll the dice from everyone (limited by MAX)
def bind_group_launch_roll(bot)
bot.on("PRIVMSG", message: /^!groll ([[:graph:]]+)(?: (\d+))? *$/) do |msg, match|
bot.on("PRIVMSG", message: /^!groll +([[:graph:]]+)(?: +(\d+))? +$/) do |msg, match|
match = match.as Regex::MatchData
limit = (match[2]? || "8").to_i
all_rolls = DB.query_all("SELECT owner, roll FROM dies WHERE name = $1",
Expand All @@ -76,7 +76,7 @@ module DashBot::Plugins::Rpg::Roll

# !droll NAME = remove the dice
def bind_del_roll(bot)
bot.on("PRIVMSG", message: /^!droll ([[:graph:]]+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!droll +([[:graph:]]+)/) do |msg, match|
msg_match = match.as Regex::MatchData
# Check if roll is in database
n = DB.query_one("SELECT COUNT(*) FROM dies WHERE name = $1 AND owner = $2",
Expand All @@ -94,7 +94,7 @@ module DashBot::Plugins::Rpg::Roll

# !lroll OWNER?
def bind_list_roll(bot)
bot.on("PRIVMSG", message: /^!lroll ([[:graph:]]+)/) do |msg, match|
bot.on("PRIVMSG", message: /^!lroll +([[:graph:]]+)/) do |msg, match|
msg_match = match.as Regex::MatchData
res = DB.query_one("SELECT roll FROM dies WHERE name = $1 AND owner = $2",
[msg_match[1], msg.source_id], as: {String})
Expand All @@ -106,7 +106,7 @@ module DashBot::Plugins::Rpg::Roll
end
end

bot.on("PRIVMSG", message: /^!lroll *$/) do |msg|
bot.on("PRIVMSG", message: /^!lroll +$/) do |msg|
# Do not trigger if the user was asking for a specific dice
rolls = DB.query_all("SELECT name, roll FROM dies WHERE owner = $1",
[msg.source_id], as: {String, String}).map { |dies| "#{dies[0]}: #{dies[1]}" }.join(", ")
Expand Down
6 changes: 3 additions & 3 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+)/) do |msg, match|
next if !authorize!(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+)/) 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+)/) do |msg, match|
next if !authorize!(msg)
match = match.as Regex::MatchData
if user_exists? match[1]
Expand Down

0 comments on commit e0bd068

Please sign in to comment.