Adds the samefag module #8
|
@ -4,7 +4,7 @@ It's like Sopel, except rewritten from scratch using Twisted as a base and over
|
|||
|
||||
## Requirements
|
||||
Python 3.6+
|
||||
Python packages: `twisted, python-dateutil, requests, bs4, wolfram, pyenchant`
|
||||
Python packages: `twisted, python-dateutil, requests, bs4, wolfram, pyenchant, http-request-randomizer`
|
||||
|
||||
## Config
|
||||
`nickname` - The nickname the bot will use.
|
||||
|
@ -49,6 +49,10 @@ tmdb_api_key = API_KEY
|
|||
|
||||
[currency]
|
||||
api_key = API_KEY
|
||||
|
||||
[samefag]
|
||||
max_queries = 10
|
||||
timeout = 360
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
|
59
modules/samefag.py
Normal file
59
modules/samefag.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
"""
|
||||
This module sends samefag votes to akun.
|
||||
Be discreet about it.
|
||||
"""
|
||||
|
||||
import time
|
||||
from http_request_randomizer.requests.proxy.requestProxy import RequestProxy
|
||||
|
||||
VOTE_URL = 'https://fiction.live/api/anonkun/voteChapter'
|
||||
|
||||
def vote(poll_id, vote_id, numvotes, timeout):
|
||||
"""
|
||||
Takes in vote identifiers and sends the
|
||||
specified number of votes through random proxies.
|
||||
Timeout is in seconds.
|
||||
Returns a string message.
|
||||
"""
|
||||
start_time = time.time()
|
||||
req_proxy = RequestProxy()
|
||||
payload = {
|
||||
'_id': poll_id,
|
||||
'vote': vote_id
|
||||
}
|
||||
i = 0
|
||||
while i < numvotes:
|
||||
request = req_proxy.generate_proxied_request(VOTE_URL, method = 'POST', data = payload, req_timeout=20)
|
||||
if request is not None and request.status_code == 200:
|
||||
i += 1
|
||||
request = None
|
||||
if time.time() - start_time > timeout:
|
||||
return "Voting timed out, " + str(i) + " votes successfully cast"
|
||||
return str(i) + " votes successfully cast"
|
||||
|
||||
@thread
|
||||
@commands('samefag')
|
||||
@example('.samefag poll_id option_id numvotes')
|
||||
@example('Illustrated guide: https://i.imgur.com/fhFI2yi.png')
|
||||
@example('.samefag hRChW6prwF7v7sNi5 21 2')
|
||||
def samefag(bot, trigger):
|
||||
"""
|
||||
Samefags votes.
|
||||
"""
|
||||
max_queries = bot.config.samefag.max_queries
|
||||
timeout = bot.config.samefag.timeout
|
||||
if not max_queries or not timeout:
|
||||
return bot.reply("Module not configured")
|
||||
max_queries = int(max_queries)
|
||||
timeout = int(timeout)
|
||||
|
||||
poll_id = trigger.group(2)
|
||||
vote_id = trigger.group(3)
|
||||
numvotes = trigger.group(4)
|
||||
try:
|
||||
numvotes = int(numvotes)
|
||||
except TypeError:
|
||||
return bot.reply("Invalid parameters")
|
||||
numvotes = min(numvotes, max_queries)
|
||||
bot.reply("Casting votes...")
|
||||
bot.reply(vote(poll_id, vote_id, numvotes, timeout))
|
Loading…
Reference in New Issue
Block a user