add colors, refactor shibe command

pull/1/head
michael 2019-09-04 12:48:49 -07:00
parent b13a206268
commit e8895ff7d6
3 changed files with 11 additions and 45 deletions

6
bot.py
View File

@ -6,6 +6,7 @@ A bot by turtlebasket
import asyncio
import json
from urllib.request import urlopen, Request
import random
import discord
from discord.ext import commands
from bot_utils import *
@ -111,8 +112,9 @@ async def shibe(ctx):
# with urllib.request.urlopen("http://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true") as json_return:
with urlopen(Request(url="http://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true", headers={'User-Agent': 'Mozilla/5.0'})) as json_return:
shibe_contents = json_return.read()
await ctx.send(embed=discord.Embed(
title="{0}, here is your random shibe:".format(ctx.message.author.name)).set_image(url=json.loads(shibe_contents)[0]))
msg="{0}, here is your random shibe:".format(ctx.message.author.name)
url=json.loads(shibe_contents)[0]
await ctx.send(embed=imgfun(msg, url))
@bot.command(aliases=['latency'])
async def ping(ctx):

View File

@ -1,3 +1,4 @@
import random
import discord
from discord.ext import commands
import asyncio
@ -53,3 +54,8 @@ async def take_vote(ctx, question:str, wait_time, min_voters):
async def improper_usage(ctx):
await ctx.send("Improper command usage! See `>>help` for more.")
def imgfun(msg:str, img_url:str):
return discord.Embed(
title=msg, color=random.randint(0, 16777215)
).set_image(url=img_url)

View File

@ -1,42 +0,0 @@
import sqlite3
connection = sqlite3.connect('storage.db')
c = connection.cursor()
c.execute
"""
import json
import bot
class server_obj:
ID = 0
MUTE_VOTE_TIME = 30
MIN_MUTE_VOTERS = 4 # should be 3
MUTE_TIME = 600 # 10 mins
KICK_VOTE_TIME = 300
MIN_KICK_VOTERS = 6
BAN_VOTE_TIME = 1200
MIN_BAN_VOTERS = 8
def __init__(self, id: int):
self.ID = id
def new_server_json(id: int):
json.dump(server_obj(id), "server_data/{}.json".format(str(id)))
def update_attribute(server: int, attrib: str, value):
try:
with open('server_data/{}.json'.format(str(server)), 'r+') as target:
json_file = json.load(target)
json_file["{}".format(attrib)] = value
json_file.close()
except FileNotFoundError:
new_server_json(id)
def load_attribute():
"""