Class: Reddit

Inherits:
Object
  • Object
show all
Defined in:
lib/reddit_auto.rb

Constant Summary collapse

PAGE_MAIN =
'https://old.reddit.com/'
PAGE_MAIN_NO_SLASH =
'https://old.reddit.com'
PAGE_MESSAGES =
'https://old.reddit.com/message/'
PAGE_SUBREDDIT =
'https://old.reddit.com/r/'
PAGE_USER =
'https://old.reddit.com/user/'
PAGE_CREATE_SUB =
'https://old.reddit.com/subreddits/create'
MESSAGE_SUBPAGES =
['inbox', 'unread', 'messages', 'comments', 'sent']
SUBREDDIT_SUBPAGES =
['hot', 'new', 'rising', 'top', 'gilded']
USER_SORTBYS =
['new', 'hot', 'top', 'controversial']
SUB_TYPES =
{
  'public' => 'type_public',
  'restricted' => 'type_restricted',
  'private' => 'type_private',
  'premium only' => 'type_gold_only'
}
CONTENT_OPTIONS =
{
  'any' => 'link_type_any',
  'links only' => 'link_type_link',
  'text posts only' => 'link_type_self'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



42
43
44
# File 'lib/reddit_auto.rb', line 42

def browser
  @browser
end

#usernameObject

Returns the value of attribute username.



43
44
45
# File 'lib/reddit_auto.rb', line 43

def username
  @username
end

Instance Method Details

#add_friendObject

Adds the currently open user as a friend, does nothing if the user is already a friend



966
967
968
969
# File 'lib/reddit_auto.rb', line 966

def add_friend
	return if is_friend
	@browser.link(text: '+ friends').click
end

#comment_has_karma(div) ⇒ Boolean

Checks if the given comment has karma

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (Boolean)

    whether the comment has karma or not



562
563
564
# File 'lib/reddit_auto.rb', line 562

def comment_has_karma(div)
	return div.span(class: 'score').present?
end

#comment_has_replies(div) ⇒ Boolean

Checks if a given comment has replies

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (Boolean)

    if the comment has replies or not



486
487
488
# File 'lib/reddit_auto.rb', line 486

def comment_has_replies(div)
	return div.attribute_value('data-replies') != '0'
end

#create_account(username, password, captcha_token) ⇒ Hash

Creates an account on reddit

Parameters:

  • username (String)

    the account’s username

  • password (String)

    the account’s password

  • captcha_token (String)

    the google’s captcha’s token, it’s up to you how to get it

Returns:

  • (Hash)

    a hash containing the account’s username and password



1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
# File 'lib/reddit_auto.rb', line 1216

def (username, password, captcha_token) #if username is nil, selects username from reddit's suggestions
	@browser.goto PAGE_MAIN
	@browser.div(id: 'header-bottom-right').link(text: 'sign up').click
	sleep 3
	@browser.button(text: 'Next').click
	sleep 5
	result = nil
	2.times do
		case get_phase
		when 'picksubs'
			phase_pick_subs
		when 'enterdata'
			break if result != nil
			result = phase_enter_data(username, password, captcha_token)
		end
		move_phase
	end
	(result['username'])
	return result
end

#create_subreddit(subreddit) ⇒ Boolean

Creates a subreddit with the given parameters

Parameters:

  • subreddit (NewSub)

    A Struct containing the subreddit’s parameters

Returns:

  • (Boolean)

    whether the subreddit was successfully created



909
910
911
912
913
914
915
916
917
918
919
920
# File 'lib/reddit_auto.rb', line 909

def create_subreddit(subreddit)
	@browser.goto CREATE_SUB_PAGE
	@browser.text_field(id: 'name').set subreddit.name
	@browser.text_field(id: 'title').set subreddit.title
	@browser.textarea(name: 'public_description').set subreddit.description
	@browser.textarea(name: 'description').set subreddit.sidebar
	@browser.textarea(name: 'submit_text').set subreddit.subtext
	@browser.radio(id: SUB_TYPES[subreddit.type]).set
	@browser.radio(id: CONTENT_OPTIONS[subreddit.content]).set
	@browser.button(text: 'create').click
	return wait_sub_creation
end

#did_create_subBoolean

Checks if the subreddit was successfully created

Returns:

  • (Boolean)

    whether the subreddit was successfully created



888
889
890
# File 'lib/reddit_auto.rb', line 888

def did_create_sub
	return @browser.p(text: 'your subreddit has been created').present?
end

#expand_all_commentsObject

Expands all comments in the open page



626
627
628
629
630
631
632
633
634
635
# File 'lib/reddit_auto.rb', line 626

def expand_all_comments
	while true
		begin
			span = @browser.span(class: 'morecomments')
			span.present? ? span.click : return
		rescue
		end
		sleep 0.5
	end
end

#form_post_url(link) ⇒ String

Forms the full post url given the post’s link

Parameters:

  • link (String)

    the post’s link

Returns:

  • (String)

    the full post url



411
412
413
# File 'lib/reddit_auto.rb', line 411

def form_post_url(link)
	return PAGE_MAIN_NO_SLASH + link
end

#form_subreddit_mod_url(subreddit) ⇒ String

Forms the full url for the subreddit’s moderator’s page

Parameters:

  • subreddit (String, Hash)

    a subreddit’s name or hash

Returns:

  • (String)

    the full url for the subreddit’s moderator’s page



826
827
828
829
830
831
832
833
# File 'lib/reddit_auto.rb', line 826

def form_subreddit_mod_url(subreddit)
  case subreddit
  when Hash
    return PAGE_SUBREDDIT + subreddit['name'] + '/about/moderators'
  when String
    return PAGE_SUBREDDIT + subreddit + '/about/moderators'
  end
end

#form_subreddit_url(name, subpage = 'hot') ⇒ String

Forms the full subreddit url given the subreddit’s name

Parameters:

  • name (String)

    the subreddit’s name

  • subpage (String) (defaults to: 'hot')

    the subreddit’s subpage, defaults to ‘hot’

Returns:

  • (String)

    the full subreddit url



776
777
778
# File 'lib/reddit_auto.rb', line 776

def form_subreddit_url(name, subpage = 'hot')
  return PAGE_SUBREDDIT + name + '/' + subpage
end

#get_activity(div) ⇒ Object

Gets a hash containing information about the given activity

Parameters:

  • div (Watir::Div)

    a div containing the activity

Returns:

  • a hash containing information about the given activity



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
# File 'lib/reddit_auto.rb', line 1109

def get_activity(div)
	result = {}
	result['type'] = get_activity_type(div)
	result['link'] = get_activity_link(div)
	result['subreddit'] = get_activity_subreddit(div)
	result['title'] = get_activity_title(div)
	result['content'] = result['type'] == 'link' ? result['title'] : get_activity_content(div)
	result['vote'] = get_activity_vote(div)
	result['karma'] = get_activity_karma(div, result['vote'])
	return result
end

#get_activity_content(div) ⇒ String

Gets the activity’s content if it is a comment

Parameters:

  • div (Watir::Div)

    the activity’s div

Returns:

  • (String)

    the activity’s text content



1053
1054
1055
# File 'lib/reddit_auto.rb', line 1053

def get_activity_content(div) #only for comments
	return div.div(class: 'usertext-body').text
end

#get_activity_divsArray

Gets all the ativity divs from the currently open user

Returns:

  • (Array)

    an array including the divs



1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/reddit_auto.rb', line 1008

def get_activity_divs
	divs = @browser.div(id: 'siteTable').children
	result = []
	divs.each do |div|
		result.push div if div.id.include? 'thing'
	end
	return result
end

#get_activity_karma(div, vote) ⇒ Integer

Gets the amount of karma the activity received, ‘up’, ‘down’ or overall

Parameters:

  • div (Watir::Div)

    a div containing the activity

  • vote (String, nil)

    ‘up’ for number of upvotes, ‘down’ for downvotes, nil for total

Returns:

  • (Integer)

    the number of votes/karma



1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
# File 'lib/reddit_auto.rb', line 1062

def get_activity_karma(div, vote)
	case get_activity_type(div)
	when 'comment' 
		return get_comment_karma(div, vote)
	when 'link'
		case vote
		when 'up' 
			return div.div(class: 'score likes').title.to_i
		when 'down' 
			return div.div(class: 'score dislikes').title.to_i
		else
			return div.div(class: 'score unvoted').title.to_i
		end
	else 
		raise 'Unknown activity type!'
	end
end

Gets the link of the activity

Parameters:

  • div (Watir::Div)

    the activity’s div

Returns:

  • (String)

    the activity’s link



1029
1030
1031
# File 'lib/reddit_auto.rb', line 1029

def get_activity_link(div)
	return div.attribute_value('data-permalink')
end

#get_activity_subreddit(div) ⇒ String

Gets the subreddit of the activity

Parameters:

  • div (Watir::Div)

    the activity’s div

Returns:

  • (String)

    the activity’s subreddit



1037
1038
1039
# File 'lib/reddit_auto.rb', line 1037

def get_activity_subreddit(div)
	return div.attribute_value('data-subreddit')
end

#get_activity_title(div) ⇒ String

Gets the title of the activity

Parameters:

  • div (Watir::Div)

    the activity’s div

Returns:

  • (String)

    the activity’s title



1045
1046
1047
# File 'lib/reddit_auto.rb', line 1045

def get_activity_title(div)
	return div.link(class: 'title').text
end

#get_activity_type(div) ⇒ String

Gets the type of the activity

Parameters:

  • div (Watir::Div)

    the activity’s div

Returns:

  • (String)

    the activity’s type



1021
1022
1023
# File 'lib/reddit_auto.rb', line 1021

def get_activity_type(div)
	return div.attribute_value('data-type')
end

#get_activity_vote(div) ⇒ String?

Gets the activity’s vote by the logged in account

Parameters:

  • div (Watir::Div)

    a div containing the activity

Returns:

  • (String, nil)

    ‘up’ if upvoted, ‘down’ if downvoted, nil if not voted



1093
1094
1095
# File 'lib/reddit_auto.rb', line 1093

def get_activity_vote(div)
	return get_comment_vote(div)
end

#get_banned_subredditsArray

Gets all the subreddits the currently logged user is banned in

Returns:

  • (Array)

    an array of strings containing the subreddits the user is banned in



1158
1159
1160
1161
1162
1163
1164
1165
# File 'lib/reddit_auto.rb', line 1158

def get_banned_subreddits
	msgs = get_messages('messages', true)
	result = []
	msgs.each do |msg|
		result.push msg['author'] if msg['content'].include?('You have been permanently banned')
	end
	return result
end

#get_comment(div) ⇒ Hash

Gets a hash containing information about a given comment

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (Hash)

    a hash containing information about a given comment



570
571
572
573
574
575
576
577
578
# File 'lib/reddit_auto.rb', line 570

def get_comment(div)
	result = {}
	result['author'] = get_comment_author(div)
	result['link'] = get_comment_link(div)
	result['content'] = get_comment_content(div)
	result['vote'] = get_comment_vote(div)
	result['karma'] = get_comment_karma(div, result['vote']) if comment_has_karma(div)
	return result
end

#get_comment_author(div) ⇒ String

Gets the author of the comment

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (String)

    the author’s username



494
495
496
# File 'lib/reddit_auto.rb', line 494

def get_comment_author(div)
	return div.attribute_value('data-author')
end

#get_comment_content(div) ⇒ String

Gets content of the comment

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (String)

    the content of the comment



510
511
512
# File 'lib/reddit_auto.rb', line 510

def get_comment_content(div)
	return div.div(class: 'usertext-body').text
end

#get_comment_karma(div, vote) ⇒ Integer

Gets the amount of karma the comment received, ‘up’, ‘down’ or overall

Parameters:

  • div (Watir::Div)

    a div containing the comment

  • vote (String, nil)

    ‘up’ for number of upvotes, ‘down’ for downvotes, nil for total

Returns:

  • (Integer)

    the number of votes/karma



519
520
521
522
523
524
525
526
527
528
529
# File 'lib/reddit_auto.rb', line 519

def get_comment_karma(div, vote)
	case vote
	when 'up'
		ind = 2
	when 'down'
		ind = 0
	else
		ind = 1
	end
	return div.p(class: 'tagline').spans(class: 'score')[ind].text.split(' ')[0].to_i
end

Gets the link of the comment

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (String)

    the link of the comment



502
503
504
# File 'lib/reddit_auto.rb', line 502

def get_comment_link(div)
	return div.attribute_value('data-permalink')
end

#get_comment_replies_count(div) ⇒ Integer

Gets the number of replies the given comment received

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (Integer)

    the number of replies



478
479
480
# File 'lib/reddit_auto.rb', line 478

def get_comment_replies_count(div)
	return div.attribute_value('data-replies').to_i
end

#get_comment_vote(div) ⇒ String?

Gets the comment’s vote by the logged in account

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (String, nil)

    ‘up’ if upvoted, ‘down’ if downvoted, nil if not voted



552
553
554
555
556
# File 'lib/reddit_auto.rb', line 552

def get_comment_vote(div)
	return 'up' if is_comment_voted(div, 'up')
	return 'down' if is_comment_voted(div, 'down')
	return nil
end

#get_comments(post, expand = false) ⇒ Array

Gets all the comments in the given post

Parameters:

  • post (String, Hash)

    a post hash or full url

  • expand (Boolean) (defaults to: false)

    whether to expand all the comments first

Returns:

  • (Array)

    an array of hashes including information about all the comments and their replies



642
643
644
645
646
# File 'lib/reddit_auto.rb', line 642

def get_comments(post, expand = false)
	open_post(post)
	expand_all_comments if expand
	return parse_comments_divs(get_comments_divs)
end

#get_comments_divsArray

Gets all the comments’ divs in the open page

Returns:

  • (Array)

    an array containing all comments’ divs in the open page



583
584
585
586
587
588
589
590
# File 'lib/reddit_auto.rb', line 583

def get_comments_divs
	divs = @browser.div(class: 'commentarea').div(class: 'sitetable nestedlisting').children
	result = []
	divs.each do |div|
		result.push div if div.attribute_value('data-type') == 'comment'
	end
	return result
end

#get_message(div) ⇒ Hash

Gets a hash object containing information about a given message

Parameters:

  • div (Watir::Div)

    the div containing the message

Returns:

  • (Hash)

    a hash containing informaton about the given message



228
229
230
231
232
233
234
235
236
237
# File 'lib/reddit_auto.rb', line 228

def get_message(div) #returns a hash with message data
	result = {}
	result['type'] = get_message_type(div)
	result['author'] = get_message_author(div)
	result['post'] = get_message_post(div) if result['type'] == 'comment'
	result['subreddit'] = result['type'] == 'comment' ? get_message_subreddit(div) : result['author']
	result['vote'] = get_message_vote(div) if result['type'] == 'comment'
	result['content'] = get_message_content(div)
	return result
end

#get_message_author(div) ⇒ String

Gets the reddit user who posted the message

Parameters:

  • div (Watir::Div)

    the div containing the message

Returns:

  • (String)

    the username of the message’s author



154
155
156
# File 'lib/reddit_auto.rb', line 154

def get_message_author(div)
	return div.attribute_value('data-author')
end

#get_message_content(div) ⇒ String

Gets the content of the message

Parameters:

  • div (Watir::Div)

    the div containing the message

Returns:

  • (String)

    the message’s content



170
171
172
# File 'lib/reddit_auto.rb', line 170

def get_message_content(div)
	return div.div(class: 'md').text
end

#get_message_divsArray<Watir::Div>

Gets all message divs in the page

Returns:

  • (Array<Watir::Div>)

    an array containing all message divs in the page



177
178
179
180
181
182
183
184
# File 'lib/reddit_auto.rb', line 177

def get_message_divs
	all_divs = @browser.div(id: 'siteTable').divs
	result = []
	all_divs.each do |div|
		result.push div if div.id.include? 'thing_'
	end
	return result
end

#get_message_post(div) ⇒ String

Gets the post that a message belongs to

Parameters:

  • div (Watir::Div)

    the div containing the message

Returns:

  • (String)

    a link to the post



146
147
148
# File 'lib/reddit_auto.rb', line 146

def get_message_post(div)
	return div.p(class: 'subject').link(class: 'title').href
end

#get_message_subreddit(div) ⇒ String

Gets the subreddit which the message was posted in

Parameters:

  • div (Watir::Div)

    the div containing the message

Returns:

  • (String)

    the subreddit



162
163
164
# File 'lib/reddit_auto.rb', line 162

def get_message_subreddit(div)
	return div.attribute_value('data-subreddit')
end

#get_message_type(div) ⇒ String

Gets the type of a message

Parameters:

  • div (Watir::Div)

    the div containing the message

Returns:

  • (String)

    the message type



138
139
140
# File 'lib/reddit_auto.rb', line 138

def get_message_type(div)
	return div.attribute_value('data-type')
end

#get_message_vote(div) ⇒ String?

Gets the type of vote the given message received from the logged in user

Parameters:

  • div (Watir::Div)

    the div containing the message

Returns:

  • (String, nil)

    returns ‘up’ or ‘down’ if voted or nil if not voted



199
200
201
202
203
# File 'lib/reddit_auto.rb', line 199

def get_message_vote(div)
	return 'up' if is_message_voted(div, 'up')
	return 'down' if is_message_voted(div, 'down')
	return nil
end

#get_messages(subpage, all_pages = false) ⇒ Array

Gets all the messages in a given subpage, raises an exception if an unknown subpage is given

Parameters:

  • subpage (String)

    the subpage to open, can be: ‘inbox’, ‘unread’, ‘messages’, ‘comments’ or ‘sent’

  • all_pages (Boolean) (defaults to: false)

    if true will check all pages, if false will check only the first page

Returns:

  • (Array)

    an array containing hashes with information about all pages



263
264
265
266
267
268
269
270
271
272
# File 'lib/reddit_auto.rb', line 263

def get_messages(subpage, all_pages = false)
	open_messages_subpage(subpage)
	result = []
	while true
		get_message_divs.each do |div|
			result.push get_message(div)
		end
		return result if !all_pages || !message_move_page('next')
	end
end

#get_moderatingArray

Gets the currently open user’s moderating pages

Returns:

  • (Array)

    an array of strings containing the names of the subreddits



950
951
952
953
954
955
956
# File 'lib/reddit_auto.rb', line 950

def get_moderating
	result = []
	@browser.ul(id: 'side-mod-list').lis.each do |li|
		result.push li.link.title.split('/')[1]
	end
	return result
end

#get_moderators(subreddit) ⇒ Array

Gets an array including the usernames of the moderators of the given subreddit

Parameters:

  • subreddit (String, Hash)

    a subreddit’s name or hash

Returns:

  • (Array)

    an array including the usernames of the moderators of the given subreddit



839
840
841
842
843
844
845
846
847
# File 'lib/reddit_auto.rb', line 839

def get_moderators(subreddit)
	@browser.goto form_subreddit_mod_url(subreddit)
	spans = @browser.div(class: 'moderator-table').spans(class: 'user')
	result = []
	spans.each do |span|
		result.push span.link.text
	end
	return result
end

#get_original_post_voteString?

Gets the type of the vote the logged in account voted the original post that is currently open

Returns:

  • (String, nil)

    returns the vote type, ‘up’ or ‘down’ or nil if not voted



392
393
394
395
396
# File 'lib/reddit_auto.rb', line 392

def get_original_post_vote
	return 'up' if is_original_post_voted('up')
	return 'down' if is_original_post_voted('down')
	return nil
end

#get_phaseObject



1206
1207
1208
# File 'lib/reddit_auto.rb', line 1206

def get_phase
	return @browser.button(class: 'c-btn c-btn-primary subreddit-picker__subreddit-button').present? ? 'picksubs' : 'enterdata'
end

#get_post(div) ⇒ Hash

Gets a hash containing information about a given post

Parameters:

  • div (Watir::Div)

    a div containing the post

Returns:

  • (Hash)

    a hash containing information about a given post



752
753
754
755
756
757
758
759
760
761
# File 'lib/reddit_auto.rb', line 752

def get_post(div)
	result = {}
	result['author'] = (div)
	result['link'] = get_post_link(div)
	result['karma'] = get_post_karma(div)
	result['title'] = get_post_title(div)
	result['vote'] = get_post_vote(div)
	result['number_of_comments'] = get_post_number_of_comments(div)
	return result
end

#get_post_author(div) ⇒ String

Gets the author of the post

Parameters:

  • div (Watir::Div)

    a div containing the post

Returns:

  • (String)

    the author of the post



687
688
689
# File 'lib/reddit_auto.rb', line 687

def (div)
	return div.attribute_value('data-author')
end

#get_post_karma(div) ⇒ Integer

Gets the amount of karma of the post

Parameters:

  • div (Watir::Div)

    a div containing the post

Returns:

  • (Integer)

    the amount of karma the post received



703
704
705
# File 'lib/reddit_auto.rb', line 703

def get_post_karma(div)
	return div.attribute_value('data-score').to_i
end

#get_post_link(div) ⇒ String

Gets the link of the post

Parameters:

  • div (Watir::Div)

    a div containing the post

Returns:

  • (String)

    the link of the post



695
696
697
# File 'lib/reddit_auto.rb', line 695

def get_post_link(div)
	return div.attribute_value('data-permalink')
end

#get_post_number_of_comments(div) ⇒ Integer

Gets the number of comments in the post

Parameters:

  • div (Watir::Div)

    a div containing the post

Returns:

  • (Integer)

    the number of comments in the post



719
720
721
# File 'lib/reddit_auto.rb', line 719

def get_post_number_of_comments(div)
	return div.attribute_value('data-comments-count').to_i
end

#get_post_title(div) ⇒ String

Gets the title of the post

Parameters:

  • div (Watir::Div)

    a div containing the post

Returns:

  • (String)

    the title of the post



711
712
713
# File 'lib/reddit_auto.rb', line 711

def get_post_title(div)
	return div.link(class: 'title').text
end

#get_post_vote(div) ⇒ String?

Gets the type of vote the post has

Parameters:

  • div (Watir::Div)

    a div containing the post

Returns:

  • (String, nil)

    the of vote, ‘up’, ‘down’ or nil if not voted



736
737
738
# File 'lib/reddit_auto.rb', line 736

def get_post_vote(div)
	return get_comment_vote(div)
end

#get_posts(subreddit, subpage = 'hot', max_pages = 1) ⇒ Array

Gets all the posts in the given subreddit

Parameters:

  • subreddit (String, Hash)

    a subreddit’s name or hash

  • subpage (String) (defaults to: 'hot')

    the subreddit’s subpage, defaults to ‘hot’

  • max_pages (Integer) (defaults to: 1)

    maximum amount of pages to gather posts from

Returns:

  • (Array)

    an array containing hashes with information about the subreddit’s posts



807
808
809
810
811
812
813
814
815
816
817
818
819
820
# File 'lib/reddit_auto.rb', line 807

def get_posts(subreddit, subpage = 'hot', max_pages = 1)
	open_subreddit(subreddit, subpage)
	result = []
	count = 0
	while true
		get_posts_divs.each do |div|
			result.push get_post(div)
		end
		count += 1
		break if count >= max_pages
		break if !subreddit_move_page('next')
	end
	return result
end

#get_posts_divsArray

Gets all the posts’ divs

Returns:

  • (Array)

    an array containing all posts’ divs



674
675
676
677
678
679
680
681
# File 'lib/reddit_auto.rb', line 674

def get_posts_divs
	divs = @browser.div(id: 'siteTable').children
	result = []
	divs.each do |div|
		result.push div if div.attribute_value('data-type') == 'link'
	end
	return result
end

#get_replies_divs(main_div) ⇒ Array

Gets all replies’ divs to the given comment

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (Array)

    an array containing all replies’ divs to the given comment



596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/reddit_auto.rb', line 596

def get_replies_divs(main_div)
	divs = main_div.div(class: 'child').div.children
	begin
		x = divs.length
	rescue
		return []
	end
	result = []
	divs.each do |div|
		result.push div if div.attribute_value('data-type') == 'comment'
	end
	return result
end

#get_reply_errorString

Gets the reason for the reply error

Returns:

  • (String)

    the reason



449
450
451
# File 'lib/reddit_auto.rb', line 449

def get_reply_error
	return @browser.span(class: 'error', style: '').split(" ")[1]
end

#get_side_barString

Gets content of the subreddit currently open sidebar

Returns:

  • (String)

    the content of the subreddit’s sidebar



866
867
868
# File 'lib/reddit_auto.rb', line 866

def get_side_bar
	return @browser.div(class: 'usertext-body').text
end

#get_subreddit(subreddit) ⇒ Hash

Gets a hash with information about the given subreddit

Parameters:

  • subreddit (String)

    the subreddit’s name

Returns:

  • (Hash)

    a hash with information about the given subreddit



874
875
876
877
878
879
880
881
882
883
# File 'lib/reddit_auto.rb', line 874

def get_subreddit(subreddit)
	result = {}
	result['name'] = subreddit
	open_subreddit(subreddit)
	result['subscribers'] = get_subscribers
	result['users_online'] = get_users_online
	result['sidebar'] = get_side_bar
	result['moderators'] = get_moderators(subreddit)
	return result
end

#get_subscribersInteger

Gets the number of subscribers the subreddit currently open has

Returns:

  • (Integer)

    the number of subscribers the subreddit currently open has



852
853
854
# File 'lib/reddit_auto.rb', line 852

def get_subscribers
	return @browser.span(class: 'subscribers').span(class: 'number').text.gsub(',', '').to_i
end

#get_user(user) ⇒ Hash

Gets a hash containing information about the given user

Parameters:

  • user (String)

    the username

Returns:

  • (Hash)

    a hash containing information about the given user



989
990
991
992
993
994
995
996
997
998
999
# File 'lib/reddit_auto.rb', line 989

def get_user(user)
	open_user_page(user)
	return nil if @browser.div(id: 'classy-error').present?
	result = {}
	result['name'] = user
	result['post_karma'] = get_user_post_karma
	result['comment_karma'] = get_user_comment_karma
	result['is_friend'] = @username ? is_friend : false
	result['moderating'] = get_moderating if is_moderator
	return result
end

#get_user_activities(user, sortby = 'new', max_pages = 1) ⇒ Array

Gets all the user activities from the given user, raises exception if unknown sorting method is used

Parameters:

  • user (String)

    the username

  • sortby (String) (defaults to: 'new')

    sorting method, can be: ‘new’, ‘hot’, ‘top’, ‘controversial’

  • max_pages (Integer) (defaults to: 1)

    maximum amounts of pages to get activies from

Returns:

  • (Array)

    an array containing all the activities hashes



1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
# File 'lib/reddit_auto.rb', line 1135

def get_user_activities(user, sortby = 'new', max_pages = 1)
	raise 'Unknown user sortby: ' + sortby if !USER_SORTBYS.include? sortby
	@browser.goto PAGE_USER + user + '/?sort=' + sortby
	result = []
	count = 0
	while true
		get_activity_divs.each do |div|
			result.push get_activity(div)
		end
		count += 1
		break if count >= max_pages
		break if !user_move_page('next')
	end
	return result
end

#get_user_comment_karmaInteger

Gets the currently open user’s comment karma

Returns:

  • (Integer)

    the currently open user’s comment karma



936
937
938
# File 'lib/reddit_auto.rb', line 936

def get_user_comment_karma
	return @browser.spans(class: 'karma')[1].text.gsub(',', '').to_i
end

#get_user_post_karmaInteger

Gets the currently open user’s post karma

Returns:

  • (Integer)

    the currently open user’s post karma



929
930
931
# File 'lib/reddit_auto.rb', line 929

def get_user_post_karma
	return @browser.span(class: 'karma').text.gsub(',', '').to_i
end

#get_users_onlineInteger

Gets the number of online users the subreddit currently open has

Returns:

  • (Integer)

    the number of online users the subreddit currently open has



859
860
861
# File 'lib/reddit_auto.rb', line 859

def get_users_online
	return @browser.p(class: 'users-online').span(class: 'number').text.gsub(',', '').to_i
end

#has_browserBoolean

Checks if the class has a browser assigned

Returns:

  • (Boolean)


48
49
50
# File 'lib/reddit_auto.rb', line 48

def has_browser
	return @browser != nil
end

#has_over_18Boolean

Checks if reddit is asking if user is over 18 for nsfw content

Returns:

  • (Boolean)

    whether the prompt is present or not



109
110
111
# File 'lib/reddit_auto.rb', line 109

def has_over_18
	return @browser.button(name: 'over18').present?
end

#has_over_18_newBoolean

Checks if reddit is asking if user is over 18 for nsfw content, uses the new interface

Returns:

  • (Boolean)

    whether the prompt is present or not



121
122
123
# File 'lib/reddit_auto.rb', line 121

def has_over_18_new
	return @browser.h3(text: 'You must be 18+ to view this community').present?
end

#has_reply(answer) ⇒ Boolean

Checks if the logged in account has already replied to the given post with the given answer

Parameters:

  • answer (String)

    the answer to look for

Returns:

  • (Boolean)

    whether or not the logged in account replied to the post with the given answer



434
435
436
437
# File 'lib/reddit_auto.rb', line 434

def has_reply(answer)
	form = @browser.form(text: answer)
	return form.present? && form.parent.parent.attribute_value('data-author') == @username
end

#has_reply_errorBoolean

Checks if there was an error when replying

Returns:

  • (Boolean)

    whether there was an error or not



442
443
444
# File 'lib/reddit_auto.rb', line 442

def has_reply_error
	return @browser.span(class: 'error', style: '').present?
end

#has_submit_errorBoolean

Checks if there was an error when submiting to a subreddit, typically because of the 10 minute cooldown between posts enforced by reddit

Returns:

  • (Boolean)

    whether there as an error or not



281
282
283
# File 'lib/reddit_auto.rb', line 281

def has_submit_error
	return @browser.span(text: 'you are doing that too much. try again in').present?
end

#is_activity_voted(div, type) ⇒ Boolean

Checks if the activity is voted by the logged in account, ‘up’ or ‘down’, raises an exception if an unknown vote type is submitted

Parameters:

  • div (Watir::Div)

    a div containing the activity

  • type (String)

    the vote type, ‘up’ or ‘down’

Returns:

  • (Boolean)

    if the activity is voted



1085
1086
1087
# File 'lib/reddit_auto.rb', line 1085

def is_activity_voted(div, type)
	return is_comment_voted(div, type)
end

#is_comment_voted(div, type) ⇒ Boolean

Checks if the comment is voted by the logged in account, ‘up’ or ‘down’, raises an exception if an unknown vote type is submitted

Parameters:

  • div (Watir::Div)

    a div containing the comment

  • type (String)

    the vote type, ‘up’ or ‘down’

Returns:

  • (Boolean)

    if the comment is voted



536
537
538
539
540
541
542
543
544
545
546
# File 'lib/reddit_auto.rb', line 536

def is_comment_voted(div, type)
	case type
	when 'up'
		buffer = 'likes'
	when 'down'
		buffer = 'dislikes'
	else
		raise 'Unknown vote type!'
	end
	return div.div(class: 'entry').attribute_value('class') == 'entry ' + buffer
end

#is_friendBoolean

Checks if the currently open user is a friend of the logged in account

Returns:

  • (Boolean)

    if the currently open user is a friend of the logged in account



961
962
963
# File 'lib/reddit_auto.rb', line 961

def is_friend
	return @browser.span(class: 'fancy-toggle-button').link(text: '- friends').attribute_value('class').include?('active')
end

#is_logged_in(username) ⇒ Boolean

Checks if a given account is logged in

Parameters:

  • username (String)

    the account’s username

Returns:

  • (Boolean)

    whether it is logged in or not



56
57
58
# File 'lib/reddit_auto.rb', line 56

def is_logged_in(username)
	return @browser.link(text: username).present?
end

#is_message_voted(div, type) ⇒ Boolean

Checks if a given message is voted by the logged in user

Parameters:

  • div (Watir::Div)

    the div containing the message

  • type (String)

    the type of vote, can be ‘up’ or ‘down’

Returns:

  • (Boolean)

    whether the message is voted in the given type



191
192
193
# File 'lib/reddit_auto.rb', line 191

def is_message_voted(div, type)
	return div.div(class: 'midcol').div(class: type + 'mod').present?
end

#is_moderatorBoolean

Checks if the currently open user is a moderator of any subreddit

Returns:

  • (Boolean)

    if the currently open user is a moderator of any subreddit



943
944
945
# File 'lib/reddit_auto.rb', line 943

def is_moderator
	return @browser.ul(id: 'side-mod-list').present?
end

#is_original_post_voted(type) ⇒ Boolean

Checks if the currently open post is voted by the logged in account, raises an exception if an unknown vote type is submitted

Parameters:

  • type (String)

    the vote type, can be ‘up’ or ‘down’

Returns:

  • (Boolean)

    whether or not the original post is voted in the given type



377
378
379
380
381
382
383
384
385
386
387
# File 'lib/reddit_auto.rb', line 377

def is_original_post_voted(type)
	div = @browser.div(id: 'siteTable').div(class: 'midcol')
	case type
	when 'up'
		return div.attribute_value('class') == 'midcol likes'
	when 'down'
		return div.attribute_value('class') == 'midcol dislikes'
	else
		raise 'Unknown vote type: ' + type
	end
end

#is_post_voted(div, type) ⇒ Boolean

Checks if the post is voted in the given type

Parameters:

  • div (Watir::Div)

    a div containing the post

  • type (String)

    the type of vote: ‘up’ or ‘down’

Returns:

  • (Boolean)

    whether the post is voted or not in the given type



728
729
730
# File 'lib/reddit_auto.rb', line 728

def is_post_voted(div, type)
	return is_comment_voted(div, type)
end

#is_submit_openBoolean

Checks if the submit page is open

Returns:

  • (Boolean)

    whether the page is open or not



288
289
290
# File 'lib/reddit_auto.rb', line 288

def is_submit_open
	return @browser.textarea(name: 'title').present? || @browser.textarea(placeholder: 'Title').present?
end

#is_subreddit_banned(subreddit) ⇒ Boolean

Checks if the given subreddit is banned

Parameters:

  • subreddit (String)

    the subreddit’s name

Returns:

  • (Boolean)

    whether the subreddit is banned or not



1251
1252
1253
1254
1255
# File 'lib/reddit_auto.rb', line 1251

def is_subreddit_banned(subreddit)
	@browser.goto PAGE_SUBREDDIT + subreddit
	skip_over_18 if has_over_18
	return @browser.h3(text: 'This community has been banned').present?
end

#is_user_banned(user) ⇒ Boolean

Checks if the given user is banned

Parameters:

  • user (String)

    the username

Returns:

  • (Boolean)

    whether the user is banned or not



1241
1242
1243
1244
1245
# File 'lib/reddit_auto.rb', line 1241

def is_user_banned(user)
	@browser.goto PAGE_USER + user
	skip_over_18 if has_over_18
	return @browser.div(id: 'classy-error').present? || @browser.h3(text: 'This account has been suspended').present?
end

#login(username, password) ⇒ Object

Logins the reddit website, raises an exception on failure

Parameters:

  • username (String)

    the account’s username

  • password (String)

    the account’s password



78
79
80
81
82
83
84
85
86
# File 'lib/reddit_auto.rb', line 78

def (username, password)
	@username = username
	@browser.goto PAGE_MAIN
	@browser.text_field(name: 'user').set username
	@browser.text_field(name: 'passwd').set password
	@browser.checkbox(id: 'rem-login-main').set
	@browser.button(text: 'login').click
	(username)
end

#logoutObject

Waits for logout, raises an exception on failure



101
102
103
104
# File 'lib/reddit_auto.rb', line 101

def logout
	@browser.link(text: 'logout').click
	wait_logout
end

#message_move_page(direction) ⇒ Boolean

Moves to the next or previous page in the message inbox

Parameters:

  • direction (String)

    the direction to move, can be ‘next’ or ‘prev’

Returns:

  • (Boolean)

    returns true if moved to the desired page or false if didn’t because you’re already in the last (move next) or first (move prev) page



243
244
245
246
247
248
# File 'lib/reddit_auto.rb', line 243

def message_move_page(direction)
	button = @browser.span(class: direction + '-button')
	result = button.present?
	button.click if result
	return result
end

#move_phaseObject



1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
# File 'lib/reddit_auto.rb', line 1189

def move_phase
	@browser.buttons(text: 'Submit').each do |button|
		if button.present?
			button.click
			sleep 5
			return
		end
	end
	@browser.buttons(text: 'Next').each do |button|
		if button.present?
			button.click
			sleep 5
			return
		end
	end
end

#open_messages_subpage(subpage) ⇒ Object

Opens the messages subpage, raises an exception if an unknown subpage is given

Parameters:

  • subpage (String)

    the subpage to open, can be: ‘inbox’, ‘unread’, ‘messages’, ‘comments’ or ‘sent’



253
254
255
256
# File 'lib/reddit_auto.rb', line 253

def open_messages_subpage(subpage)
	raise 'Unknown message subpage: ' + subpage if !MESSAGE_SUBPAGES.include? subpage
	@browser.goto PAGE_MESSAGES + subpage
end

#open_post(post) ⇒ Object

Opens the given post

Parameters:

  • post (Hash, String)

    accepts either a post hash or the post’s full url



418
419
420
421
422
423
424
425
426
427
428
# File 'lib/reddit_auto.rb', line 418

def open_post(post)
   case post
   when Hash
     @browser.goto form_post_url(post['link'])
   when String
     @browser.goto post
   else
     return
   end
   skip_over_18 if has_over_18
end

#open_subreddit(subreddit, subpage = 'hot') ⇒ Object

Opens the given subreddit in the given subpage, raises an exception if an unknown subpage is given, known subpages: ‘hot’, ‘new’, ‘rising’, ‘top’, ‘gilded’

Parameters:

  • subreddit (String, Hash)

    a subreddit’s name or hash

  • subpage (String) (defaults to: 'hot')

    the subreddit’s subpage, defaults to ‘hot’



784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
# File 'lib/reddit_auto.rb', line 784

def open_subreddit(subreddit, subpage = 'hot')
	raise 'Unknown subreddit subpage: ' + subpage if !SUBREDDIT_SUBPAGES.include? subpage
   case subreddit
   when Hash
     @browser.goto form_subreddit_url(subreddit['name'], subpage)
   when String
     if subreddit.include? '/'
       @browser.goto subreddit
     else
       @browser.goto form_subreddit_url(subreddit, subpage)
     end
   else
     return
   end
	skip_over_18 if has_over_18
end

#open_user_page(user) ⇒ Object

Opens the page of the given username

Parameters:

  • user (String)

    the username



980
981
982
983
# File 'lib/reddit_auto.rb', line 980

def open_user_page(user)
	@browser.goto PAGE_USER + user
	skip_over_18 if has_over_18
end

#parse_comments_divs(divs) ⇒ Array

Parses all the comments divs and replies

Parameters:

  • div (Watir::Div)

    a div containing the comment

Returns:

  • (Array)

    an array of hashes containing the comments and their replies



614
615
616
617
618
619
620
621
622
623
# File 'lib/reddit_auto.rb', line 614

def parse_comments_divs(divs)
	result = []
	divs.each do |div|
		result.push get_comment(div)
		if comment_has_replies(div)
			result[result.length-1]['replies'] = parse_comments_divs(get_replies_divs(div))
		end
	end
	return result
end

#phase_enter_data(username, password, captcha_token) ⇒ Object



1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
# File 'lib/reddit_auto.rb', line 1171

def phase_enter_data(username, password, captcha_token)
	result = {}
	if username == nil
		link = @browser.link(class: 'username-generator__item')
		result['username'] = link.text
		link.click
	else
		result['username'] = username
		@browser.text_field(id: 'user_reg').set username
	end
	@browser.text_field(id: 'passwd_reg').set password
	result['password'] = password
	sleep 5
	@browser.execute_script(%{document.getElementById("g-recaptcha-response").innerHTML="} + captcha_token + %{"})
	sleep 5
	return result
end

#phase_pick_subsObject



1167
1168
1169
# File 'lib/reddit_auto.rb', line 1167

def phase_pick_subs
	@browser.execute_script("var buttons = document.getElementsByClassName('c-btn c-btn-primary subreddit-picker__subreddit-button');\nfor (var i = 0; i < 8; i++) {\nbuttons[i].click();\n}")
end

#remove_friendObject

Removes the currently open user as a friend, does nothing if the user is not a friend



972
973
974
975
# File 'lib/reddit_auto.rb', line 972

def remove_friend
	return if !is_friend
	@browser.link(text: '- friends').click
end

#reply_comment(div, answer) ⇒ Object

Replies the given comment with the given anwer

Parameters:

  • div (Watir::Div)

    a div containing the comment

  • answer (String)

    the answer



652
653
654
655
656
# File 'lib/reddit_auto.rb', line 652

def reply_comment(div, answer)
	div.li(text: 'reply').click
	div.textarea(name: 'text').set answer
	div.button(class: 'save').click
end

#reply_message(div, answer) ⇒ Object

Replies the given message

Parameters:

  • div (Watir::Div)

    the div containing the message

  • answer (String)

    answer, the content of the reply



218
219
220
221
222
# File 'lib/reddit_auto.rb', line 218

def reply_message(div, answer)
	div.li(text: 'reply').click
	div.textarea.set answer
	div.button(text: 'save').click
end

#reply_post(post, answer) ⇒ Boolean

Replies the given post

Parameters:

  • post (Hash, String)

    the post to reply, can be a post hash or full url

  • answer (String)

    the answer to the post

Returns:

  • (Boolean)

    if replying as successful



467
468
469
470
471
472
# File 'lib/reddit_auto.rb', line 467

def reply_post(post, answer)
   open_post(post)
	@browser.div(class: 'commentarea').textarea(name: 'text').set answer
	@browser.div(class: 'commentarea').button(text: 'save').click
	return wait_reply
end

#set_flair(flair) ⇒ Object

Sets the given flair to the post, does nothing if the subreddit has no flair option

Parameters:

  • flair (String)

    the desired flair



326
327
328
329
330
331
332
333
334
335
# File 'lib/reddit_auto.rb', line 326

def set_flair(flair)
	return if !sub_has_flair
	@browser.div('aria-label': 'Add flair').click
	if flair == nil
		@browser.div('aria-label': 'flair_picker').div.click
	else
		@browser.div('aria-label': 'flair_picker').span(text: flair).click
	end
	@browser.button(text: 'Apply').click
end

#skip_over_18Object

Skips the are you over 18 prompt



114
115
116
# File 'lib/reddit_auto.rb', line 114

def skip_over_18
	@browser.button(text: 'continue').click
end

#skip_over_18_newObject

Skips the are you over 18 prompt, uses the new interface



126
127
128
# File 'lib/reddit_auto.rb', line 126

def skip_over_18_new
	@browser.link(text: 'Yes').click
end

#sub_has_flairBoolean

Checks if the subreddit has an option to add a flair to posts

Returns:

  • (Boolean)

    whether or not it has a flair option



319
320
321
# File 'lib/reddit_auto.rb', line 319

def sub_has_flair
	return !@browser.div('aria-label': 'Not available for this community').present?
end

Submits a link to the given subreddit, raises an exception on failure

Parameters:

  • subreddit (String)

    the name of the subreddit to submit the link to

  • url (String)

    the url to submit

  • title (String)

    the title of the post



307
308
309
310
311
312
313
314
# File 'lib/reddit_auto.rb', line 307

def submit_link(subreddit, url, title)
	@browser.goto PAGE_SUBREDDIT + subreddit + '/submit'
	skip_over_18 if has_over_18
	@browser.text_field(id: 'url').set url
	@browser.textarea(name: 'title').set title
	@browser.button(name: 'submit').click
	wait_submit
end

Submits a link to the given subreddit using the new interface, raises an exception on failure

Parameters:

  • subreddit (String)

    the name of the subreddit to submit the link to

  • url (String)

    the url to submit

  • title (String)

    the title of the post

  • flair (String, nil) (defaults to: nil)

    the flair to add, if nil will add no flair to the post



343
344
345
346
347
348
349
350
351
352
353
# File 'lib/reddit_auto.rb', line 343

def submit_link_new(subreddit, url, title, flair = nil) #uses new reddit
	@browser.goto 'https://www.reddit.com/r/' + subreddit + '/submit'
	skip_over_18_new if has_over_18_new
	blink = @browser.button(text: 'Link')
	blink.click if blink.present?
	@browser.textarea(placeholder: 'Title').set title
	@browser.textarea(placeholder: 'Url').set url
	set_flair(flair)
	@browser.buttons(text: 'Post')[1].click
	wait_submit
end

#submit_text(subreddit, title, text) ⇒ Object

Submits a text post to the given subreddit, raises an exception on failure

Parameters:

  • subreddit (String)

    the name of the subreddit to submit the link to

  • title (String)

    the title of the post

  • text (String)

    the text content of the post



360
361
362
363
364
365
366
367
# File 'lib/reddit_auto.rb', line 360

def submit_text(subreddit, title, text)
	@browser.goto PAGE_SUBREDDIT + subreddit + '/submit?selftext=true'
	skip_over_18 if has_over_18
	@browser.textarea(name: 'title').set title
	@browser.textarea(name: 'text').set text
	@browser.button(name: 'submit').click
	wait_submit
end

#subreddit_move_page(direction) ⇒ Boolean

Moves to the next or previous page in the subreddit

Parameters:

  • direction (String)

    the direction to move, can be ‘next’ or ‘prev’

Returns:

  • (Boolean)

    returns true if moved to the desired page or false if didn’t because you’re already in the last (move next) or first (move prev) page



767
768
769
# File 'lib/reddit_auto.rb', line 767

def subreddit_move_page(direction)
	return message_move_page(direction)
end

#user_move_page(direction) ⇒ Boolean

Moves to the next or previous page in the user’s activity box

Parameters:

  • direction (String)

    the direction to move, can be ‘next’ or ‘prev’

Returns:

  • (Boolean)

    returns true if moved to the desired page or false if didn’t because you’re already in the last (move next) or first (move prev) page



1125
1126
1127
# File 'lib/reddit_auto.rb', line 1125

def user_move_page(direction)
	return message_move_page(direction)
end

#vote_activity(div, type) ⇒ Object

Votes the given activity

Parameters:

  • div (Watir::Div)

    a div containing the activity

  • the (String)

    vote type can be ‘up’ or ‘down’



1101
1102
1103
# File 'lib/reddit_auto.rb', line 1101

def vote_activity(div, type)
	vote_message(div, type)
end

#vote_comment(div, type) ⇒ Object

Votes the given comment

Parameters:

  • div (Watir::Div)

    a div containing the comment

  • type (String)

    the vote type can be ‘up’ or ‘down’



662
663
664
665
# File 'lib/reddit_auto.rb', line 662

def vote_comment(div, type)
	return if is_comment_voted(div, type)
	div.div(class: 'midcol').div(class: type).click
end

#vote_message(div, type) ⇒ Object

Votes the given message

Parameters:

  • div (Watir::Div)

    the div containing the message

  • type (String)

    the type of vote, can be ‘up’ or ‘down’



209
210
211
212
# File 'lib/reddit_auto.rb', line 209

def vote_message(div, type)
	return if is_message_voted(div, type)
	div.div(class: 'midcol').div(class: type).click
end

#vote_original_post(type) ⇒ Object

Votes the currently open original post, does nothing if already voted, raises an exception if an unknown vote type is submitted

Parameters:

  • type (String)

    vote type: ‘up’ or ‘down’



401
402
403
404
405
# File 'lib/reddit_auto.rb', line 401

def vote_original_post(type)
	return if is_original_post_voted(type)
	div = @browser.div(id: 'siteTable').div(class: 'midcol')
	div.div(class: type).click
end

#vote_post(div, type) ⇒ Object

Votes the given post, ‘up’ or ‘down’, raises exception if unknown vote type is sumited

Parameters:

  • div (Watir::Div)

    a div containing the post

  • type (String)

    the type of vote: ‘up’ or ‘down’



744
745
746
# File 'lib/reddit_auto.rb', line 744

def vote_post(div, type)
	vote_comment(div, type)
end

#wait_login(username) ⇒ Object

Waits for a successful loggin, raises an exception if it fails to login

Parameters:

  • username (String)

    the account’s username



63
64
65
66
67
68
69
70
71
72
# File 'lib/reddit_auto.rb', line 63

def (username)
	count = 0.0
	while !is_logged_in(username)
		sleep 0.25
		count += 0.25
		if count > 10
			raise 'Reddit login failed for username: ' + username
		end
	end
end

#wait_logoutObject

Waits for logout, raises an exception on failure



89
90
91
92
93
94
95
96
97
98
# File 'lib/reddit_auto.rb', line 89

def wait_logout
	count = 0.0
	while is_logged_in(@username)
		sleep 0.25
		count += 0.25
		if count > 10
			raise 'Reddit logout failed for username: ' + @username
		end
	end
end

#wait_reply(time = 2) ⇒ Boolean

Sleeps the given time then checks if there was an error when replying

Parameters:

  • time (Integer) (defaults to: 2)

    the number of seconds to sleep

Returns:

  • (Boolean)

    whether there was an error or not



457
458
459
460
# File 'lib/reddit_auto.rb', line 457

def wait_reply(time = 2)
	sleep time
	return !has_reply_error
end

#wait_sub_creationBoolean

Waits for the creation of the subreddit

Returns:

  • (Boolean)

    whether the subreddit was successfully created



895
896
897
898
899
900
901
902
903
# File 'lib/reddit_auto.rb', line 895

def wait_sub_creation
	count = 0.0
	while true
		return true if did_create_sub
		sleep 0.25
		count += 0.25
		return false if count >= 10
	end
end

#wait_submitObject

Waits for the submit page to open, raises an exception if it fails to open after 10 seconds



293
294
295
296
297
298
299
300
# File 'lib/reddit_auto.rb', line 293

def wait_submit
	count = 0.0
	while is_submit_open
		sleep 0.25
		count += 0.25
		raise 'Post submission failed!' if count >= 10
	end
end