Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
first half of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
djetelina committed Jun 3, 2016
1 parent ef9db73 commit 056ff8b
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 179 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea/
log.txt
cogs/avatar/
cogs/db/
tokens.py
10 changes: 7 additions & 3 deletions channels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
channels = {
"admin": "176304607172100097",
"news": "179963038781276160",
"private": "179945195280924673",
"public": "176293292865093632",
"rules": "179965419728273408"
"general": "176293292865093632",
"rules": "179965419728273408",
"gaming": "179945195280924673",
"tabletop": "188081332834926592",
"technology": "188085243478147074",
"programming": "188083195470807040",
"giveaways": "188087131070005248"
}
5 changes: 3 additions & 2 deletions checks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from discord.ext import commands
import discord.utils
import id_settings as id
import id_settings as our_id


def is_idiotech():
"""
Expand Down Expand Up @@ -34,7 +35,7 @@ def predicate(ctx):


def is_owner_check(message):
return message.author.id == id.owner_id
return message.author.id == our_id.owner_id


def is_owner():
Expand Down
95 changes: 0 additions & 95 deletions cogs/additional.py

This file was deleted.

26 changes: 13 additions & 13 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def youtube(self):
month = calendar.month_name[int(month)] # takes month number and returns word form (i.e. 05 = may)

uploaded = mo + "Uploaded: " + mo + "{} the {}{}, {}.".format(month, day, get_date_suf(day), year)
link = "https://youtu.be/" + data["items"][0]["id"]["videoId"]
link = "https://youtu.be/" + data["items"][0]["our_id"]["videoId"]
# uses ``` to stop video from being embed

await s.destructmsg(title + "\n" + uploaded + "\n\n"+link, 30, self.bot)
Expand Down Expand Up @@ -282,28 +282,28 @@ def calc_until(rd):
:return: three strings with time left
"""

tdelta = rd - datetime.utcnow()
tstr = str(tdelta)
t_delta = rd - datetime.utcnow()
t_str = str(t_delta)

test_var = tstr.split(".")[0]
if len(test_var) == 7 or len(test_var) == 8: # is there is still hours in the time left
test_var = t_str.split(".")[0]
if len(test_var) == 7 or len(test_var) == 8:
days = "0 days"
hrs, mins, secs = test_var.split(":")
elif len(test_var) == 5 or len(test_var) == 4: # if there is still minutes in the time left
hrs, minutes, secs = test_var.split(":")
elif len(test_var) == 5 or len(test_var) == 4:
days = "0 days"
hrs = "0"
mins, secs = test_var.split(":")
elif len(test_var) == 1 or len(test_var) == 2: # if there are still seconds remaining until launch
minutes, secs = test_var.split(":")
elif len(test_var) == 1 or len(test_var) == 2:
days = "0 days"
hrs = "0"
mins = "0"
minutes = "0"
else:
days, notdays = tstr.split(",")
hrs, mins, secs = notdays.split(":")
days, time = t_str.split(",")
hrs, minutes, secs = time.split(":")

hrs = hrs.strip() # removes spaces in string

return days, hrs, mins
return days, hrs, minutes


def calc_duration(start):
Expand Down
54 changes: 21 additions & 33 deletions cogs/giveaway.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

# List with running giveaway instances
giveawayslist = []
# Channels where we are allowed to host giveaways
whitechannels = ['private', 'admin']
loop = asyncio.get_event_loop()


Expand Down Expand Up @@ -110,7 +108,7 @@ class Giveaways:
def __init__(self, bot):
self.bot = bot

@commands.group(pass_context=True, description=desc.giveaway, brief=desc.giveawayb)
@commands.group(pass_context=True, description=desc.giveaway, brief=desc.giveaway_brief)
async def giveaway(self, ctx):
if ctx.invoked_subcommand is None:
if len(giveawayslist) > 0:
Expand All @@ -127,67 +125,57 @@ async def giveaway(self, ctx):
await s.destructmsg(reply, 10, self.bot)

@giveaway.command(name="open", pass_context=True, description=desc.openga, brief=desc.opengab)
async def _open(self, ctx, channel: str, countdown: int, *, game: str):
async def _open(self, ctx, countdown: int, *, game: str):
has_opened = False
for giveaway in giveawayslist:
if ctx.message.author == giveaway.owner:
has_opened = True

if not has_opened:
try:
destination = self.bot.get_channel(chan.channels[channel])
if channel in whitechannels:
Giveaway(game, countdown, destination, ctx.message.author, self.bot)
await s.whisper(ctx.message.author, """I have prepared the giveaway.
If you want me to automatically PM the winner the code please use:
`!giveaway code <CODE>`
Giveaway(game, countdown, self.bot.get_channel(chan.channels['giveaways']), ctx.message.author, self.bot)
await s.whisper(ctx.message.author, """I have prepared the giveaway.
If you want to add a link to the game's page (like steam url) please use:
This message will show once after you open the giveaway:
`!giveaway link <URL>`
If you want me to automatically PM the winner the code please use:
`!giveaway code <CODE>`
If you want to add a link to the game's page (like steam url) please use:
This message will show once after you open the giveaway:
`!giveaway link <URL>`
If you want to say more about the game or a giveaway, like where is it redeemable,
if you are also giving away DLC with it etc.
You can also include url here instead of using the previous command
This message will show once after you open the giveaway:
`!giveaway description <DESCRIPTION>`
If you want to say more about the game or a giveaway, like where is it redeemable,
if you are also giving away DLC with it etc.
You can also include url here instead of using the previous command
This message will show once after you open the giveaway:
`!giveaway description <DESCRIPTION>`
I will open the enrollments to your giveaway after you send me `!giveaway confirm`
""", self.bot)

I will open the enrollments to your giveaway after you send me `!giveaway confirm`
""", self.bot)

else:
await s.whisper(
ctx.message.author, "I'm sorry, but you can't open a giveaway in this channel.", self.bot)

except KeyError:
await s.whisper(ctx.message.author, "I don't know channel *{}*".format(channel), self.bot)

else:
await s.whisper(ctx.message.author, "You already have one giveaway open", self.bot)

@giveaway.command(name="link", pass_context=True, description=desc.linkga, brief=desc.linkga)
@giveaway.command(name="link", pass_context=True, description=desc.link_ga, brief=desc.link_ga)
async def _link(self, ctx, url: str):
for giveaway in giveawayslist:
if ctx.message.author == giveaway.owner:
giveaway.url = url
await s.whisper(giveaway.owner, "Link accepted", self.bot)

@giveaway.command(name="code", pass_context=True, description=desc.codega, brief=desc.codegab)
@giveaway.command(name="code", pass_context=True, description=desc.code_ga, brief=desc.code_ga_brief)
async def _code(self, ctx, *, code: str):
for giveaway in giveawayslist:
if ctx.message.author == giveaway.owner:
giveaway.code = code
await s.whisper(giveaway.owner, "Code accepted", self.bot)

@giveaway.command(name="description", pass_context=True, description=desc.descga, brief=desc.descga)
@giveaway.command(name="description", pass_context=True, description=desc.desc_ga, brief=desc.desc_ga)
async def _description(self, ctx, *, description: str):
for giveaway in giveawayslist:
if ctx.message.author == giveaway.owner:
giveaway.description = description
await s.whisper(giveaway.owner, "Description accepted", self.bot)

@giveaway.command(name="confirm", pass_context=True, description=desc.confirmga, brief=desc.confirmga)
@giveaway.command(name="confirm", pass_context=True, description=desc.confirm_ga, brief=desc.confirm_ga)
async def _confirm(self, ctx):
for giveaway in giveawayslist:
if ctx.message.author == giveaway.owner:
Expand All @@ -210,7 +198,7 @@ async def _cancel(self, ctx):
await ga.cancel()
await s.whisper(ga.owner, "Giveaway canceled", self.bot)

@commands.command(pass_context=True, description=desc.enroll, brief=desc.enrollb)
@commands.command(pass_context=True, description=desc.enroll, brief=desc.enroll_brief)
async def enroll(self, ctx, *, game: str):
user = ctx.message.author
found = 0
Expand Down
68 changes: 68 additions & 0 deletions cogs/overwatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from discord.ext import commands
import descriptions as desc
import bs4
import requests
import asyncio


class Overwatch:
def __init__(self, bot):
"""
Edit self.dates with releases we want to track
"""
self.bot = bot

@commands.command(description=desc.ow, brief=desc.owb)
async def overwatch(self, region: str, battletag: str):
msg = await self.bot.say("Fetching Stats for {}".format(battletag))

user = battletag.replace("#", "-")

reg_eu = ["eu", "euro", "europe"]
reg_us = ["australia", "aussie", "aus", "us", "usa", "na", "america", "au"]
reg_kr = ["asia", "korea", "kr", "as", "china", "japan"]

if region.lower() in reg_eu:
reg = "eu"
elif region.lower() in reg_us:
reg = "us"
elif region.lower() in reg_kr:
reg = "kr"
else:
self.bot.edit_message(msg, "Unknown region: {}".format(region))
return

loop = asyncio.get_event_loop()
future = loop.run_in_executor(
None, requests.get, "https://playoverwatch.com/en-us/career/pc/{}/{}".format(reg, user))
res = await future

try:
res.raise_for_status()
except Exception as e:
await self.bot.edit_message(msg, "**Error with request. Please check for mistakes before trying again.**"
".\nError: "+str(e))
return

doc = bs4.BeautifulSoup(res.text, "html.parser")
page = doc.select('div')
most_played = page[82].select('div')[2].getText()
most_games = page[82].select('div')[3].getText()
game_swon = int(page[1111].select('div')[0].select('td')[1].getText())
games_played = int(page[1111].select('div')[0].select('td')[3].getText())
time_played = page[1111].select('div')[0].select('td')[11].getText()
games_lost = games_played - game_swon
won_lost = "{}/{}".format(game_swon, games_lost)

await self.bot.edit_message(msg, "**Overwatch Stats for {} - {}**\n\n"
"Time Played: *{}*\n"
"Total Games: *{}*\n"
"Games Won/Lost: *{}*\n"
"Most Played Hero: *{}, {} played*"
"".format(battletag, reg.upper(), time_played, games_played,
won_lost, most_played, most_games))


def setup(bot):
bot.add_cog(Overwatch(bot))

2 changes: 2 additions & 0 deletions cogs/restricted.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import descriptions as desc
import channels as chan
import discord
import os


class Restricted:
Expand Down Expand Up @@ -76,6 +77,7 @@ async def log(self, users: str):
with open("log.txt", "rb") as logfile:
await self.bot.send_file(admin, logfile, filename="log.txt",
content="Log file for mentioned users from last 500 messages in public channel.")
os.remove("log.txt")


def setup(bot):
Expand Down
1 change: 1 addition & 0 deletions cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sqlite3
import os


class Stats:
def __init__(self, bot):
self.bot = bot
Expand Down

0 comments on commit 056ff8b

Please sign in to comment.