Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked !pm command to behave more robust #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.all
:ll => Command.new(ServerGroup.normal) { |nicks| list_urls(nicks) }, # list links
:rs => Command.new(ServerGroup.normal) { |keyword| crawl_for(keyword, 1) }, # random shit
:rsi => Command.new(ServerGroup.normal) { crawl_img },
:pm => Command.new(ServerGroup.normal) { |args| pm_to(args[0], args[1]) },
:pm => Command.new(ServerGroup.normal) { |args| pm_to(args) },
:rsw => Command.new(ServerGroup.normal) { crawl_wtf },
:ot => Command.new(ServerGroup.normal) { open_terminal},
:dd => Command.new(ServerGroup.server_admin) { |nick| drag_and_drop(nick.first) },
Expand Down Expand Up @@ -225,9 +225,33 @@ def self.let_bot_say(sender, msg)
Bot.say_as_poke(sender, msg)
end

# Fuzzy matching private message sending via pigeon
def self.pm_to(fuzzy_nick, msg)
matched_users = User.try_find_all_by_nick(fuzzy_nick)
# Send a private message to a target user via Pigeon.
#
# @example Send the user Heman the message "and I say hey...*sing*"
# !pm Heman, and I say hey...*sing*
#
# @info: Message format: <NICK>,<MESSAGE>
# a substring matching the target user nick
# followed by the message that should be sent to the target,
# seperated by a ,
# The message is sent to every user nickname that matches
# with msg[0].
# args is a string array containing the target user and the message
# Pigeon is supposed to send.
# @param args [Array<String>] the pm arguments.
def self.pm_to(args)
matched_users = User.try_find_all_by_nick(args.first)
msg = args[1..-1].join(" ")
if matched_users.empty? or args.any? { |a| a.include?(",") }
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always contains the sentinel

content = args.join(" ").split(",")
fuzzy_nick = content.first.strip
m = User.try_find_all_by_nick(fuzzy_nick)
if !m.empty? && !m.any? do |u| u.sentinel? end
matched_users = m
msg = content[1..-1].join(" ")
end
end
return if matched_users.empty?
sender = Command.sender
header = "#{sender.nick} sent you: "
matched_users.each do |user|
Expand Down
4 changes: 4 additions & 0 deletions src/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def initialize(id, nick, permissions, channel_id, unique_id, is_nil_user=false)
reset_rtd_count
end

def sentinel?
@is_nil_user
end

# Increments the rtd counter of this user by 1.
#
# @info: The rtd (roll the dice) counter determines
Expand Down