Class: Cosgrove::Bot
- Inherits:
-
Discordrb::Commands::CommandBot
- Object
- Discordrb::Commands::CommandBot
- Cosgrove::Bot
- Includes:
- SnarkCommands, Support
- Defined in:
- lib/cosgrove/bot.rb
Constant Summary
Constants included from SnarkCommands
Instance Method Summary collapse
- #add_all_commands ⇒ Object
- #add_all_messages ⇒ Object
-
#initialize(options = {}) ⇒ Bot
constructor
A new instance of Bot.
Methods included from SnarkCommands
Methods included from Support
#append_link_details, #cannot_find_input, #find_account, #last_irreversible_block, #muted, #page_views, #send_url, #skip_channel, #skipped_channel?, #skipped_channels, #start_typing, #suggest_account_name, #unknown_account
Methods included from Utils
#api, #chain_options, #core_asset, #cycle_api_at, #cycle_stream_at, #debt_asset, #find_author, #find_author_name_permlink, #find_comment, #find_comment_by_slug, #find_transfer, #follow_api, #head_block_number, #hive_engine, #hive_engine_blockchain, #hive_engine_contracts, #hive_engine_shutdown, #last_irreversible_block_num, #new_tx, #parse_slug, #ping_api, #properties, #reset_api, #reset_stream, #steem_engine, #steem_engine_blockchain, #steem_engine_contracts, #steem_engine_shutdown, #stream, #to_rep
Methods included from Config
#channel_disable_comment_voting, #channel_upvote_weight, #cosgrove_allow_pm_commands, #cosgrove_client_id, #cosgrove_disable_comment_voting, #cosgrove_operators, #cosgrove_secure, #cosgrove_token, #cosgrove_upvote_weight, #discord_channels, #discord_fancy_log, #discord_log_mode, #hive_account, #hive_api_failover_urls, #hive_api_url, #hive_engine_api_url, #hive_posting_wif, #meeseeker_url, #steem_account, #steem_api_failover_urls, #steem_api_url, #steem_engine_api_url, #steem_posting_wif, #test_api_failover_urls, #test_api_url, #test_posting_wif
Constructor Details
#initialize(options = {}) ⇒ Bot
Returns a new instance of Bot.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cosgrove/bot.rb', line 14 def initialize( = {}) [:token] ||= cosgrove_token [:client_id] ||= cosgrove_client_id super() @on_success_upvote_job = [:on_success_upvote_job] @on_success_register_job = [:on_success_register_job] self.bucket :voting, limit: 4, time_span: 8640, delay: 10 add_all_commands SnarkCommands::add_all_snark_commands(self) end |
Instance Method Details
#add_all_commands ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cosgrove/bot.rb', line 38 def add_all_commands self.command :help do |_event, *args| help = [] help << "`$slap [target]` - does a slap on the `target`" help << "`$verify <account> [chain]` - check `account` association with Discord users (`chain` default `steem`)" help << "`$register <account> [chain]` - associate `account` with your Discord user (`chain` default `steem`)" help << "`$upvote [url]` - upvote from #{hive_account}; empty or `^` to upvote last steemit link" help.join("\n") end self.command :version do |_| "cosgrove: #{Cosgrove::VERSION} :: https://github.com/steem-third-party/cosgrove" end self.command :verify do |event, key, chain = :hive| return if event.channel.pm? && !cosgrove_allow_pm_commands cb_account = nil if key.nil? event.respond "To create an account: https://hive.blog/enter_email?r=#{hive_account}" return end account = find_account(key, event) if !!account && account.respond_to?(:name) cb_account = Cosgrove::Account.new(account.name, chain) else discord_id = key.split('@').last.split('>').first.to_i cb_account = Cosgrove::Account.find_by_discord_id(discord_id, chain) end account = cb_account.chain_account if account.nil? && !!cb_account if !!account && !!cb_account && cb_account.discord_ids.any? if cb_account.hidden? "#{chain.to_s.upcase} account `#{account.name}` has been registered." else discord_ids = cb_account.discord_ids.map { |id| "<@#{id}>" } "#{chain.to_s.upcase} account `#{account.name}` has been registered with #{discord_ids.to_sentence}." end elsif !!account "#{chain.to_s.upcase} account `#{account.name}` has not been registered with any Discord account. To register:\n`$register #{account.name}`" elsif discord_id.to_i > 0 "<@#{discord_id}> has not been associated with a #{chain.to_s.upcase} account. To register:\n`$register <account>`" else "No association found. To register:\n`$register <account>`" end end self.command :register do |event, account_name, chain = :hive| return if event.channel.pm? && !cosgrove_allow_pm_commands discord_id = event..id if discord_id.to_i == 0 event.respond 'Problem with discord id.' return end account = find_account(account_name, event, chain) if account.nil? event.respond 'Try again later.' return end cb_account = Cosgrove::Account.new(account.name, chain) if cb_account.discord_ids.include? discord_id event.respond "Already registered `#{account.name}` on `#{chain.upcase}` with <@#{discord_id}>" return end memo_key = cb_account.memo_key(discord_id) op = find_transfer(chain: chain, account: hive_account, from: account.name, to: hive_account, memo_key: memo_key) if !!op cb_account.add_discord_id(discord_id) if !!@on_success_register_job begin @on_success_register_job.call(event, cb_account) rescue => e ap e ap e.backtrace end end "Ok. #{chain.to_s.upcase} account #{account.name} has been registered with <@#{discord_id}>." else "To register `#{account.name}` with <@#{discord_id}>, send `0.001 #{core_asset}` or `0.001 #{debt_asset}` to `#{hive_account}` with memo: `#{memo_key}`\n\nThen type `$register #{account.name}` again." end end self.command(:upvote, bucket: :voting, rate_limit_message: 'Sorry, you are in cool-down. Please wait %time% more seconds.') do |event, slug = nil| return if event.channel.pm? && !cosgrove_allow_pm_commands slug = Cosgrove::latest_steemit_link[event.channel.name] if slug.nil? || slug.empty? || slug == '^' = { on_success: @on_success_upvote_job } Cosgrove::UpvoteJob.new().perform(event, slug) end end |
#add_all_messages ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/cosgrove/bot.rb', line 29 def # A user typed a link to steemit.com (or some condenser site) self.(content: /http[s]*:\/\/.*\/(.*\/)?@.+\/.+/, ignore_bots: false) do |event| link = event.content.split(' ').first Cosgrove::latest_steemit_link[event.channel.name] = link append_link_details(event, link) end end |