How to use the twitchio.ext.commands.cog 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 / interactions.py View on Github external
from twitchio.ext import commands

@commands.cog()
class Interactions:
	
	def __init__(self, bot):
		self.bot = bot
	
	@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!")
	
	@commands.command(aliases = ("hi",))
	async def hello(self, ctx, *, user = None):
		if not user or user.lower() == "harmonbot":
			await ctx.send(f"Hello, {ctx.author.name.capitalize()}!")
github Harmon758 / Harmonbot / Twitch / cogs / time.py View on Github external
from twitchio.ext import commands

import datetime
import sys

import dateutil.easter

sys.path.insert(0, "..")
from units.location import get_geocode_data, get_timezone_data, UnitOutputError
from units.time import duration_to_string
sys.path.pop(0)

@commands.cog()
class Time:
	
	def __init__(self, bot):
		self.bot = bot
	
	@commands.command(aliases = ("bday",))
	async def birthday(self, ctx, month : int = None, day : int = None):
		# TODO: Document
		# TODO: Add ability to reset
		# TODO: Handle leap day
		# TODO: Add custom birthday ability for any viewer
		now = datetime.datetime.utcnow()
		if ctx.author.name == ctx.channel.name and month and day:
			try:
				date = datetime.date(year = now.year, month = month, day = day)
			except ValueError as e:
github Harmon758 / Harmonbot / Twitch / cogs / runescape.py View on Github external
from twitchio.ext import commands

import bisect
import datetime
import sys
import time

sys.path.insert(0, "..")
from units.runescape import get_ge_data, get_monster_data, UnitOutputError
from units.time import duration_to_string
sys.path.pop(0)

@commands.cog()
class Runescape:
	
	def __init__(self, bot):
		self.bot = bot
		
		self.ehp_data = {"attack": ((0, 15000), (37224, 38000), (100000, 55000), (1000000, 65000), (1986068, 82000), 
									(3000000, 95000), (5346332, 115000), (13034431, 180000)), 
						"strength": ((0, 15000), (37224, 38000), (100000, 55000), (1000000, 65000), (1986068, 82000), 
										(3000000, 95000), (5346332, 115000), (13034431, 180000)), 
						"ranged": ((0, 250000), (6517253, 330000), (13034431, 900000)), 
						"prayer": ((0, 850000), (737627, 1600000)), 
						"cooking": ((0, 40000), (7842, 130000), (37224, 175000), (737627, 490000), (1986068, 950000)), 
						"woodcutting": ((0, 7000), (2411, 16000), (13363, 35000), (41171, 49000), (302288, 126515), 
										(737627, 137626), (1986068, 149906), (5902831, 160366), (13034431, 200000)), 
						"fletching": ((0, 30000), (969, 45000), (33648, 150000), (50339, 250000), (150872, 500000), 
										(302288, 700000), (13034431, 4000000)),
github Harmon758 / Harmonbot / Twitch / cogs / search.py View on Github external
from twitchio.ext import commands

@commands.cog()
class Search:
	
	def __init__(self, bot):
		self.bot = bot
	
	@commands.command()
	async def google(self, ctx, *search):
		await ctx.send("https://google.com/search?q=" + '+'.join(search))
	
	@commands.command()
	async def imfeelinglucky(self, ctx, *search):
		await ctx.send("https://google.com/search?btnI&q=" + '+'.join(search))
	
	@commands.command()
	async def lmgtfy(self, ctx, *search):
		await ctx.send("https://lmgtfy.com/?q=" + '+'.join(search))
github Harmon758 / Harmonbot / Twitch / cogs / twitch.py View on Github external
from twitchio.ext import commands

import datetime
import sys

import dateutil.parser

sys.path.insert(0, "..")
from units.time import duration_to_string
sys.path.pop(0)

@commands.cog()
class Twitch:
	
	def __init__(self, bot):
		self.bot = bot
	
	@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.")
github Harmon758 / Harmonbot / Twitch / cogs / location.py View on Github external
from twitchio.ext import commands

import datetime
import sys

import pyowm

sys.path.insert(0, "..")
from units.location import wind_degrees_to_direction
sys.path.pop(0)

@commands.cog()
class Location:
	
	def __init__(self, bot):
		self.bot = bot
	
	# TODO: almanac? - record highs and lows
	#       format: KTUL Airport: Normal High: 85°F/29°C, Normal Low: 64°F/17°C | Record High: 106°F/41°C in 1911, Record Low: 50°F/10°C in 1998
	#       error formats: Location Not Found. Try location near an airport.
	#                      {Location} Found. No data provided.
	# TODO: alert(s)? - weather alerts in area
	#       format: New York City: 2 Alerts: Winter Weather Advisory till 2:00 AM EST on March 04, 2015 | Winter Weather Advisory till 2:00 AM EST on March 04, 2015 | Use * !alertinfo * for alert details
	#               New York City: No Alerts
	# TODO: alert(s)info? - detailed report of alerts in area
	#       format: Jefferson City, Missouri: 1 Alerts | * Winter Weather Advisory * from 3:12 PM CST on December 17, 2014 till 10:00 AM CST on December 18, 2014 ...Winter Weather Advisory remains in effect from midnight tonight to 10 am CST Thursday... * timing...snow will spread across the area tonight and continue through mid-morning on Thursday. * Accumulations...1 to 2 inches of snow. * Winds...east 5 mph or less. * Impacts...the wintry precipitation will result in hazardous travel conditions on bridges...overpasses...and untreated roads. Parking lots and sidewalks will become slippery as well. Precautionary/preparedness actions... A Winter Weather Advisory is issued for a variety of winter weather conditions...such as snow...blowing snow...sleet...or freezing drizzle and rain. It only takes a small amount of wintry precipitation to make roads...bridges...sidewalks...and parking lots icy and dangerous. It is often difficult to tell when ice begins to form...so do not be caught off guard.
	#               Jefferson City, Missouri: No Alerts
github Harmon758 / Harmonbot / Twitch / cogs / words.py View on Github external
from twitchio.ext import commands

import textwrap

# TODO: Create words unit
# TODO: Use wordnik library?

@commands.cog()
class Words:
	
	def __init__(self, bot):
		self.bot = bot
	
	@commands.command()
	async def define(self, ctx, *, word):
		url = f"http://api.wordnik.com:80/v4/word.json/{word}/definitions"
		params = {"limit": 1, "includeRelated": "false", "useCanonical": "false", "includeTags": "false", 
					"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 not data:
			return await ctx.send("Definition not found.")