How to use the twitchio.ext.commands function in twitchio

To help you get started, we’ve selected a few twitchio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Harmon758 / Harmonbot / Twitch / cogs / location.py View on Github external
	@commands.command()
	async def forecast(self, ctx, *, location = ""):
		# TODO: Detailed forecast option?
		if not location or location.lower() == ctx.channel.name:
			location = await self.bot.db.fetchval("SELECT location FROM twitch.locations WHERE channel = $1", ctx.channel.name)
			if not location:
				return await ctx.send(f"Error: Location not specified")
		try:
			forecaster = self.bot.owm_client.daily_forecast(location)
		except (pyowm.exceptions.api_response_error.NotFoundError, 
				pyowm.exceptions.api_call_error.BadGatewayError) as e:
			# TODO: Catch base exceptions?
			return await ctx.send(f"Error: {e}")
		forecast = forecaster.get_forecast()
		location = forecast.get_location()
		output = f"{location.get_name()}, {location.get_country()}"
		for weather in forecast:
github Harmon758 / Harmonbot / Twitch / cogs / twitch.py View on Github external
	@commands.command()
	async def averagefps(self, ctx):
		users = await self.bot.get_users(ctx.channel.name)
		url = "https://api.twitch.tv/kraken/streams/" + users[0].id
		params = {"client_id": self.bot.http.client_id}
		headers = {"Accept": "application/vnd.twitchtv.v5+json"}
		async with self.bot.aiohttp_session.get(url, params = params, headers = headers) as resp:
			data = await resp.json()
		stream = data.get("stream")
		if not stream:
			return await ctx.send("Average FPS not found.")
		await ctx.send(f"Average FPS: {stream['average_fps']}")
github Harmon758 / Harmonbot / Twitch / cogs / time.py View on Github external
	@commands.command()
	async def time(self, ctx, *, location = ""):
		if not location or location.lower() == ctx.channel.name:
			location = await self.bot.db.fetchval("SELECT location FROM twitch.locations WHERE channel = $1", ctx.channel.name)
			if not location:
				return await ctx.send(f"Error: Location not specified")
		try:
			geocode_data = await get_geocode_data(location, aiohttp_session = self.bot.aiohttp_session)
			latitude = geocode_data["geometry"]["location"]["lat"]
			longitude = geocode_data["geometry"]["location"]["lng"]
			timezone_data = await get_timezone_data(latitude = latitude, longitude = longitude, 
													aiohttp_session = self.bot.aiohttp_session)
		except UnitOutputError as e:
			return await ctx.send(f"Error: {e}")
		location_time = datetime.datetime.now(datetime.timezone(datetime.timedelta(
						seconds = timezone_data["dstOffset"] + timezone_data["rawOffset"])))
		# TODO: Use method for Discord time command
github Harmon758 / Harmonbot / Twitch / cogs / interactions.py View on Github external
	@commands.command(aliases = ("goodbye",))
	async def bye(self, ctx, *, user = None):
		if not user or user.lower() == "harmonbot":
			await ctx.send(f"Bye, {ctx.author.name.capitalize()}!")
		else:
			await ctx.send(f"{user.title().lstrip('/')}, {ctx.author.name.capitalize()} says goodbye!")
github Harmon758 / Harmonbot / Twitch / cogs / words.py View on Github external
	@commands.command(aliases = ("audiodefine", "pronounce"))
	async def pronunciation(self, ctx, word):
		# TODO: Add phonetic/text pronunciation
		url = f"http://api.wordnik.com:80/v4/word.json/{word}/audio"
		params = {"useCanonical": "false", "limit": 1, "api_key": self.bot.WORDNIK_API_KEY}
		async with self.bot.aiohttp_session.get(url, params = params) as resp:
			if resp.status == 404:
				return await ctx.send("Error: Not found")
			data = await resp.json()
			if resp.status == 429:
				return await ctx.send(f"Error: {data['message']}")
		if data:
			await ctx.send(f"{data[0]['word'].capitalize()}: {data[0]['fileUrl']}")
		else:
			await ctx.send("Word or audio not found.")
github Harmon758 / Harmonbot / Twitch / cogs / runescape.py View on Github external
	@commands.command()
	async def cache(self, ctx):
		seconds = int(10800 - time.time() % 10800)
		# 10800 = seconds in 3 hours
		await ctx.send(f"{duration_to_string(datetime.timedelta(seconds = seconds))} until Guthixian Cache.")
github Harmon758 / Harmonbot / Twitch / cogs / runescape.py View on Github external
	@commands.command()
	async def zybez(self, ctx):
		return await ctx.send("See https://forums.zybez.net/topic/1783583-exit-post-the-end/")