def check(client): config = config_h.get() if not "hereApiToken" in config: print( "No Here API-token found, a new one can be created at developer.here.com" ) return False return True
def check(client): config = config_h.get() if not client.db.exists(): return False if not "nexusApiToken" in config: return False return True
async def post_updates(self): config = config_h.get() header = { "apiKey": config["nexusApiToken"], "User-Agent": config['apiUserAgentIdentification'] } async with self.lock: async with self.client.db.begin() as conn: result = await conn.stream(self.update_table.select()) prune, updated = await self._check_for_updates(header, result) await self._prune(conn, prune) await self._update(conn, updated)
async def subscribe_mod(self, ctx, mod: nexus_mod, channel: discord.TextChannel = None): if not mod: raise ModError(f"The given mod is not valid") if not channel: channel = ctx.channel elif ctx.guild != channel.guild: raise ChannelError("The given channel is not in this server") config = config_h.get() request = urllib.request.Request( headers={ "apiKey": config["nexusApiToken"], "User-Agent": config['apiUserAgentIdentification'] }, url=f"{self.api_url}games/{mod[0]}/mods/{mod[1]}.json") response = await util_h.read_website_content(request, dict) if response.get("code", 200) == 404: raise ModError(response["message"]) async with self.lock: async with self.client.db.begin() as conn: try: await conn.execute(self.update_table.insert().values( channel_id=channel.id, game_domain=mod[0], mod_id=mod[1], updated=response["updated_timestamp"])) except sa.exc.IntegrityError: raise ModError(( f"The given mod has already been subscribed to in {channel.mention}" )) await ctx.send( f"\"{response['name']}\" has been added to the update list in {channel.mention}" )
import itertools import discord import random from async_timeout import timeout from functools import partial from common.util_h import * from common import config_h from discord.ext import commands from datetime import timedelta from math import ceil """ Variables """ conf = config_h.get() ffmpeg_options = conf['ffmpeg_options'] ffmpeg_before_options = conf['ffmpeg_before_options'] ytdl = youtube_dl.YoutubeDL(conf['ytdlFormatOptions']) class SongList(): def __init__(self, audioJsonPath, audiopath): print(audiopath) self.audiopath = audiopath self.audioJsonPath = audioJsonPath audioSongsJson = self.importAudioJSON() audioSongsFiles = self.importAudioFiles() self.songs = self.mergeAudioLists(audioSongsJson, audioSongsFiles) self.exportAudioJson()
def main(): config = config_h.get() client = MrRoboto(config) client.run(config['discordToken'], reconnect=True)
async def weather(self, ctx, *, search: str): """Returns weather for given position""" lat = "59.9170" lon = "10.7274" config = config_h.get() # Get coordinates # A Rest API Key from developer.here.com here_api_token = config["hereApiToken"] here_api_url = f"https://discover.search.hereapi.com/v1/discover?at={lat},{lon}&limit=1&q={urllib.parse.quote_plus(search)}&apiKey={here_api_token}" # Fetch data json_content = await util_h.read_website_content(here_api_url, dict) result_coords = json_content["items"][0]["position"] result_loc = json_content["items"][0]["address"] # Fetch data search_request = urllib.request.Request( headers={"User-Agent": config['apiUserAgentIdentification']}, url= f"https://api.met.no/weatherapi/locationforecast/2.0/compact.json?lat={round(result_coords['lat'],3)}&lon={round(result_coords['lng'],3)}" ) json_content = await util_h.read_website_content(search_request, dict) meta = json_content["properties"]["meta"] timeseries = json_content["properties"]["timeseries"] # Removing some unneeded data ¯\_(ツ)_/¯ data = [] for time in timeseries: # only checking temp midday cause I'm lazy and probably good enough, might implement properly some other time if time["time"].endswith("T12:00:00Z"): data.append(time) embed = discord.Embed( title=f"Weather Forecast for {result_loc['label']}") dateformat = "%Y-%m-%dT%H:%M:%fZ" # Adding to embeds for day in data: day_name = (datetime.datetime.strptime(day["time"], dateformat)).strftime("%A") extra_note = "" # Why not check windspeeds as well if day["data"]["instant"]["details"]["wind_speed"] > 32.6: extra_note = f"{day['data']['instant']['details']['wind_speed']} {meta['units']['wind_speed']} winds" # This should reaaaally not be so long - Fredrico embed.add_field( name=day_name, value= f"{day['data']['instant']['details']['air_temperature']} {meta['units']['air_temperature']}\n{day['data']['next_6_hours']['details']['precipitation_amount']} {meta['units']['precipitation_amount']}\n{day['data']['next_6_hours']['summary']['symbol_code']} {extra_note}" ) # Sending :) await ctx.send(embed=embed)