Class: Cosgrove::Account
Constant Summary
collapse
- DISCORD_IDS =
'discord_ids'.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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(account_name, chain = :hive) ⇒ Account
Returns a new instance of Account.
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cosgrove/account.rb', line 14
def initialize(account_name, chain = :hive)
@chain = chain.to_sym
raise "Unknown Chain: #{@chain}" unless Cosgrove::KNOWN_CHAINS.include? @chain
@account_name = account_name.to_s.downcase
@discord_ids = []
if !!details
@discord_ids = details[DISCORD_IDS] || []
end
end
|
Instance Attribute Details
#account_name ⇒ Object
Returns the value of attribute account_name
12
13
14
|
# File 'lib/cosgrove/account.rb', line 12
def account_name
@account_name
end
|
#discord_ids ⇒ Object
Returns the value of attribute discord_ids
12
13
14
|
# File 'lib/cosgrove/account.rb', line 12
def discord_ids
@discord_ids
end
|
Class Method Details
.find_by_discord_id(discord_id, chain = :hive) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/cosgrove/account.rb', line 26
def self.find_by_discord_id(discord_id, chain = :hive)
return if Account.chain_data(chain.to_s).nil?
discord_id = discord_id.to_s.split('@').last.split('>').first.to_i
return nil if discord_id == 0
Account.chain_data(chain.to_s).each do |k, v|
ids = v[DISCORD_IDS]
return Account.new(k, chain) if !!ids && ids.include?(discord_id)
end
return nil
end
|
.find_by_memo_key(memo_key, secure, chain = :hive) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/cosgrove/account.rb', line 41
def self.find_by_memo_key(memo_key, secure, chain = :hive)
Account.chain_data(chain.to_s).each do |k, v|
v[DISCORD_IDS].each do |discord_id|
return Account.new(k, chain) if Account.gen_memo_key(k, discord_id, secure, chain) == memo_key
end
end
return nil
end
|
Instance Method Details
#add_discord_id(discord_id) ⇒ Object
#chain_account ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/cosgrove/account.rb', line 76
def chain_account
return @chain_account if !!@chain_account
if !!@account_name
api(@chain).get_accounts([@account_name]) do |accounts, errors|
@chain_account = accounts.first
end
end
end
|
#details(chain = :hive) ⇒ Object
51
52
53
54
|
# File 'lib/cosgrove/account.rb', line 51
def details(chain = :hive)
Account.chain_data(chain.to_s)[@account_name] ||= {}
Account.chain_data(chain.to_s)[@account_name]
end
|
#hidden? ⇒ Boolean
56
57
58
|
# File 'lib/cosgrove/account.rb', line 56
def hidden?
!!details['hidden']
end
|
#memo_key(discord_id) ⇒ Object
72
73
74
|
# File 'lib/cosgrove/account.rb', line 72
def memo_key(discord_id)
Account.gen_memo_key(@account_name, discord_id, cosgrove_secure, @chain)
end
|
#novote? ⇒ Boolean
60
61
62
|
# File 'lib/cosgrove/account.rb', line 60
def novote?
!!details['novote']
end
|