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

Commit

Permalink
Merge pull request #13 from ExtraRandom/master
Browse files Browse the repository at this point in the history
Fixes !release bug
  • Loading branch information
David Jetelina authored and David Jetelina committed May 23, 2016
2 parents 1a40c64 + 4fc13ad commit b6d4cab
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 39 deletions.
41 changes: 28 additions & 13 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, bot):
# Dates have to be in relation to UTC (so if release is 5am BST, it would be 4am UTC)
self.dates = {
"Overwatch": datetime(2016, 5, 23, 23, 0, 0), # launches 12:00am bst, -1 because its in UTC time
"Total War: Warhammer": datetime(2016, 5, 24, 0, 0, 0),
"Total War: Warhammer": datetime(2016, 5, 24, 7, 0, 0),
"Hearts of Iron 4": datetime(2016, 6, 6, 0, 0, 0),
"No Man's Sky": datetime(2016, 6, 21, 0, 0, 0),
"Deus Ex: Mankind Divided": datetime(2016, 8, 23, 0, 0, 0),
Expand All @@ -28,15 +28,18 @@ def __init__(self, bot):
}

@commands.command(description=desc.reddit, brief=desc.reddit)
async def reddit(self):
async def reddit(self): # returns link to sub-reddit
await s.destructmsg("https://www.reddit.com/r/idiotechgaming/", 20, self.bot)

@commands.command(description=desc.github, brief=desc.github)
async def github(self):
await s.destructmsg("https://github.com/iScrE4m/IdiotechDiscordBot", 20, self.bot)
async def github(self): # returns link to github for this bot
await s.destructmsg("You can request features, contribute and report issues with the bot here:"
"\nhttps://github.com/iScrE4m/IdiotechDiscordBot", 20, self.bot)

@commands.command(description=desc.twitch, brief=desc.twitchb)
async def twitch(self):
# finds status of Idiotech's twitch stream
# if live, it will return amount of viewers, current stream up-time and game being played
with aiohttp.ClientSession() as session:
async with session.get('https://api.twitch.tv/kraken/streams?channel=idiotechgaming')as resp:
data = await resp.json()
Expand All @@ -47,6 +50,7 @@ async def twitch(self):
fmt = "%Y-%m-%dT%H:%M:%SZ"
hrs, mins, secs = calc_duration(datetime.strptime(data["streams"][0]["created_at"], fmt))

# if one person is watching return 'person' instead of people
if views == 1:
peep = "person"
else:
Expand All @@ -60,11 +64,11 @@ async def twitch(self):
await s.destructmsg(reply, 20, self.bot)

@commands.command(description=desc.twitter, brief=desc.twitter)
async def twitter(self):
async def twitter(self): # returns link to Idiotech's twitter
await s.destructmsg('https://twitter.com/idiotechgaming', 20, self.bot)

@commands.command(description=desc.fb, brief=desc.fb)
async def facebook(self):
async def facebook(self): # finds latest facebbok post and returns it, along with link to page
with aiohttp.ClientSession() as session:
async with session.get('https://graph.facebook.com/v2.6/idiotechgaming/posts'
'?access_token={}'.format(t.fb_key)) as resp:
Expand All @@ -83,6 +87,9 @@ async def facebook(self):

@commands.command(description=desc.youtube, brief=desc.youtube)
async def youtube(self):
# finds information on latest upload from Idiotech's youtube channel
#

connector = aiohttp.TCPConnector(verify_ssl=False)

with aiohttp.ClientSession(connector=connector) as session:
Expand All @@ -93,7 +100,8 @@ async def youtube(self):

mo = "**" # Modifier (e.g. * for italic, ** for bold, __ for underline and so on)
title = mo + "Latest Upload: " + mo\
+ data["items"][0]["snippet"]["title"] # [::-1] # msg + vid title, [::-1] reverses str
+ data["items"][0]["snippet"]["title"] # [::-1] # msg + vid title, [::-1] reverses str

uploaded = data["items"][0]["snippet"]["publishedAt"] # datetime video was uploaded
date = str(uploaded).split('T')[0] # just the date of upload

Expand Down Expand Up @@ -188,13 +196,13 @@ async def release(self, ctx):
if len(arg) > 0:
for game in self.dates:
if game.lower().startswith(arg.lower()) or game.lower() is arg.lower():

days, hrs, mins = calc_until(self.dates[game])
msg = "Error in command 'release', string 'msg' not changed."
# ^^ if for some reason the below code doesnt set the message properly

if int_day(days) < 0: # if hours is a minus (i.e. game is released)
msg = "{} is out now!".format(game)
else:
msg = "{} releases in {},{} hours and {} minutes.".format(game, days, hrs, mins)
msg = "{} releases in {}, {} hours and {} minutes.".format(game, days, hrs, mins)
await s.destructmsg(msg, 30, self.bot)

break
Expand All @@ -205,7 +213,7 @@ async def release(self, ctx):

for game, time in sorted(self.dates.items(), key=lambda x: x[1]):
days, hrs, mins = calc_until(self.dates[game])
msg += "\n{} releases in {},{} hours and {} minutes.".format(game, days, hrs, mins)
msg += "\n{} releases in {}, {} hours and {} minutes.".format(game, days, hrs, mins)

await s.destructmsg("```{}```".format(msg), 30, self.bot)

Expand Down Expand Up @@ -268,8 +276,15 @@ def calc_until(rd):
tdelta = rd - datetime.utcnow()
tstr = str(tdelta)

days, notdays = tstr.split(",")
hrs, mins, secs = notdays.split(":")
test_var = tstr.split(".")[0]
if len(test_var) == 8: # if 8 characters long (meaning 0 days left):
days = "0 days"
hrs, mins, secs = test_var.split(":")
else:
days, notdays = tstr.split(",")
hrs, mins, secs = notdays.split(":")

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

return days, hrs, mins

Expand Down
37 changes: 15 additions & 22 deletions cogs/weather.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""
================================================
REQUIRES INSTALLATION OF PYCOUNTRY
================================================
"""

from discord.ext import commands
import simplify as s
import aiohttp
Expand Down Expand Up @@ -35,16 +27,17 @@ async def weather(self, *, loc: str): # loc = location
async with session.get(weather_api)as resp:
data = await resp.json()

temp = data["main"]["temp"]
temp = data["main"]["temp"] # temperature in kelvin, converted later in code
brief = data["weather"][0]["main"] # ie cloudy
desc = data["weather"][0]["description"] # ie very cloudy/ overcast clouds and so on
name = data["name"] # will return name without '_' and with capitalised words, saves effort
cloud = str(data["clouds"]["all"])
cloud = str(data["clouds"]["all"]) # gets cloud percentage
country = pycountry.countries.get(alpha2=data["sys"]["country"])
# gets country name from country code returned by api

desc = capital_everything(desc)
cel = to_1dp(str(kel_to_cel(temp)))
fah = to_1dp(str(cel_to_fah(cel)))
desc = capital_everything(desc) # returns description with capitals on all words
cel = to_1dp(str(kel_to_cel(temp))) # converts temp from kelvin to celsius
fah = to_1dp(str(cel_to_fah(cel))) # converts cel temp from celsius to fahrenheit

await s.destructmsg("__**{}, {} - Weather Status**__\n"
"**Temperature:** {}c - {}f\n"
Expand All @@ -68,7 +61,7 @@ def kel_to_cel(kelvin):
:param kelvin:
:return: Celsius:
"""
result = float(kelvin) - 273.15
result = float(kelvin) - 273.15 # the conversion of kelvin to celsius
return result


Expand All @@ -79,24 +72,24 @@ def cel_to_fah(cels):
:param cels: Celsius
:return: Fahrenheit:
"""
result = (float(cels)*1.8) + 32
result = (float(cels)*1.8) + 32 # the conversion of celsius to fahrenheit
return result


def capital_everything(string):
"""
Takes a string, such as "hello world" and capitalizes each world
returning "Hello World" in this example
returning "Hello World" for example
:param string:
:return: The capitalized words in a string:
"""
listy = string.split() # () is same as " " apparently
new_list = []
for word in listy:
listy = string.split() # () is same as " "
new_list = [] # new list to put strings from old list into once capitalised
for word in listy: # for each word, capitalise then add to list
thing = word.capitalize()
new_list.append(thing)
result = ' '.join(new_list)
result = ' '.join(new_list) # merge list into one string
return result


Expand All @@ -108,6 +101,6 @@ def to_1dp(value):
:return: string of number to 1 decimal point
"""
before, after = str(value).split(".")
after = after[0:1]
result = before + "." + after
after = after[0:1] # returns characters 1 and 2 of string (counts from 0 so character 1 is 0 and 2 is 1 etc)
result = before + "." + after # visually turn back into a decimal number
return result
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Idiotech's Discord Bot

Bot for Discord server of Idiotech
Bot for [Idiotech's Discord Server](https://discord.gg/0z3KQXI6apyyeNOD)

## Rules for developing

Expand Down
9 changes: 8 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
# Taken from main.py

# Which extensions to load on startup
extensions = ['cogs.giveaway', 'cogs.general', 'cogs.restricted', 'cogs.stats', ]
extensions = [
'cogs.giveaway',
'cogs.general',
'cogs.restricted',
'cogs.stats',
'cogs.weather',
'cogs.swear',
]
# Status message for bot
now_playing = "!help"

Expand Down
4 changes: 2 additions & 2 deletions simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

async def destructmsg(msg, seconds, bot):
"""
Send autodestructive message to channel of original message
Send an auto-destructive message to channel of original message
:param msg: String
:param seconds: Integer of seconds after which to delete the message
Expand All @@ -15,7 +15,7 @@ async def destructmsg(msg, seconds, bot):

async def whisper(user, msg, bot):
"""
Send private message to a user
Send a private message to a user
:param user: User object
:param msg: String
Expand Down

0 comments on commit b6d4cab

Please sign in to comment.