Compare commits

...

3 Commits

Author SHA1 Message Date
382b3ce179 add ship quirks command 2020-02-26 11:33:50 -05:00
90d59aff50 bandaid to fix coinlib's api 2020-02-26 11:33:29 -05:00
784310e162 bugfix argparse import 2020-02-26 11:32:30 -05:00
3 changed files with 22 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import config
from module import commands, example, require_admin
URI = "https://coinlib.io/api/v1"
HEADERS = {'cookie': "SESSIONID=91049a9e2e89f6a39f827378dd10184f;"}
@commands("crypto", "coin")
@example(".crypto btc",
@ -28,7 +29,7 @@ def crypto(bot, trigger):
symbol = trigger.args[1]
if symbol:
params["symbol"] = symbol
res = requests.get(URI + "/coin", params=params)
res = requests.get(URI + "/coin", params=params, headers=HEADERS)
if res.status_code in [400, 401]:
return bot.msg(f"Error: {res.json()['error']}")
res.raise_for_status()

View File

@ -46,3 +46,22 @@ def magic(bot, trigger):
if num >= len(data)-1:
num = len(data)-1
bot.msg(data[num])
@commands("ship")
def magic(bot, trigger):
"""
Prints a ship quirk. If an index is not given, a random one is chosen.
"""
with open(os.path.join(bot.static, "ship_quirks.txt"), "r") as file:
data = file.read().splitlines()
num = None
try:
num = int(trigger.args[1]) - 1
except (IndexError, ValueError):
pass
if num == None:
num = random.randint(0, len(data)-1)
if num >= len(data)-1:
num = len(data)-1
bot.msg(data[num])

View File

@ -3,6 +3,7 @@
Google translate that shit.
"""
import random
import argparse
import requests