Class: Lich::DragonRealms::CharacterValidator

Inherits:
Object
  • Object
show all
Defined in:
documented/dragonrealms/commons/common-validation.rb

Overview

Validates character information and manages communication with the lnet script.

See Also:

Constant Summary collapse

LNET_SCRIPT_NAME =
'lnet'
FIND_NOT_FOUND =
'There are no adventurers in the realms that match the names specified'

Instance Method Summary collapse

Constructor Details

#initialize(announce, should_sleep, greet, name) ⇒ void

Initializes a new CharacterValidator instance.

Parameters:

  • announce (Boolean)

    whether to announce the character's status

  • should_sleep (Boolean)

    whether to put the script to sleep

  • greet (Boolean)

    whether to greet the character

  • name (String)

    the name of the character



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'documented/dragonrealms/commons/common-validation.rb', line 17

def initialize(announce, should_sleep, greet, name)
  waitrt?
  fput('sleep') if should_sleep

  @lnet = (Script.running + Script.hidden).find { |val| val.name == LNET_SCRIPT_NAME }
  @validated_characters = []
  @greet = greet
  @name = name

  unless lnet_available?
    Lich::Messaging.msg("bold", "CharacterValidator: lnet is not running. Chat features will be unavailable.")
    return
  end

  send_chat("#{@name} is up and running in room #{Room.current.id}! Whisper me 'help' for more details.") if announce
end

Instance Method Details

#confirm(character) ⇒ void

This method returns an undefined value.

Confirms the validation of the specified character and optionally greets them.

Parameters:

  • character (String)

    the name of the character to confirm



59
60
61
62
63
64
65
66
67
68
# File 'documented/dragonrealms/commons/common-validation.rb', line 59

def confirm(character)
  return if valid?(character)

  Lich::Messaging.msg("plain", "CharacterValidator: Successfully validated: #{character}")
  @validated_characters << character

  return unless @greet

  put "whisper #{character} Hi! I'm your friendly neighborhood #{@name}. Whisper me 'help' for more details. Don't worry, I've memorized your name so you won't see this message again."
end

#in_game?(character) ⇒ Boolean

Checks if the specified character is currently in the game.

Parameters:

  • character (String)

    the name of the character to check

Returns:

  • (Boolean)

    true if the character is in the game, false otherwise



116
117
118
119
# File 'documented/dragonrealms/commons/common-validation.rb', line 116

def in_game?(character)
  result = DRC.bput("find #{character}", FIND_NOT_FOUND, /^\s{2}#{character}\.$/, 'Unknown command')
  result =~ /^\s{2}#{character}\.$/
end

#send_bankbot_balance(character, balance) ⇒ void

This method returns an undefined value.

Sends the current bank balance to the specified character.

Parameters:

  • character (String)

    the name of the character to send the balance to

  • balance (Integer)

    the current balance to send



81
82
83
84
85
86
87
# File 'documented/dragonrealms/commons/common-validation.rb', line 81

def send_bankbot_balance(character, balance)
  return unless lnet_available?

  message = "Current Balance: #{balance}"
  Lich::Messaging.msg("plain", "CharacterValidator: Attempting to DM #{character} with message: #{message}")
  send_chat_to(character, message)
end

#send_bankbot_help(character, messages) ⇒ void

This method returns an undefined value.

Sends help messages to the specified character.

Parameters:

  • character (String)

    the name of the character to send help to

  • messages (Array<String>)

    the list of messages to send



104
105
106
107
108
109
110
111
# File 'documented/dragonrealms/commons/common-validation.rb', line 104

def send_bankbot_help(character, messages)
  return unless lnet_available?

  messages.each do |message|
    Lich::Messaging.msg("plain", "CharacterValidator: Attempting to DM #{character} with message: #{message}")
    send_chat_to(character, message)
  end
end

#send_bankbot_location(character) ⇒ void

This method returns an undefined value.

Sends the current location to the specified character.

Parameters:

  • character (String)

    the name of the character to send the location to



92
93
94
95
96
97
98
# File 'documented/dragonrealms/commons/common-validation.rb', line 92

def send_bankbot_location(character)
  return unless lnet_available?

  message = "Current Location: #{Room.current.id}"
  Lich::Messaging.msg("plain", "CharacterValidator: Attempting to DM #{character} with message: #{message}")
  send_chat_to(character, message)
end

#send_slack_token(character) ⇒ void

This method returns an undefined value.

Sends the Slack token to the specified character.

Parameters:

  • character (String)

    the name of the character to send the token to



37
38
39
40
41
42
43
# File 'documented/dragonrealms/commons/common-validation.rb', line 37

def send_slack_token(character)
  return unless lnet_available?

  message = "slack_token: #{UserVars.slack_token || 'Not Found'}"
  Lich::Messaging.msg("plain", "CharacterValidator: Attempting to DM #{character} with message: #{message}")
  send_chat_to(character, message)
end

#valid?(character) ⇒ Boolean

Checks if the specified character has been validated.

Parameters:

  • character (String)

    the name of the character to check

Returns:

  • (Boolean)

    true if the character is validated, false otherwise



73
74
75
# File 'documented/dragonrealms/commons/common-validation.rb', line 73

def valid?(character)
  @validated_characters.include?(character)
end

#validate(character) ⇒ void

This method returns an undefined value.

Validates the specified character by checking if they are already validated.

Parameters:

  • character (String)

    the name of the character to validate



48
49
50
51
52
53
54
# File 'documented/dragonrealms/commons/common-validation.rb', line 48

def validate(character)
  return if valid?(character)
  return unless lnet_available?

  Lich::Messaging.msg("plain", "CharacterValidator: Attempting to validate: #{character}")
  @lnet.unique_buffer.push("who #{character}")
end