Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
chatbot/chatbot/discordbot.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
237 lines (181 sloc)
8.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord ##for discord | |
from discord.ext import commands ## for discord | |
import json # for json files | |
import requests ## for API | |
import random | |
import secretkeys ## for API keys | |
import botfunctions as idk ## for botfunctions.py functions | |
import asyncio | |
##import matplotlib as plt | |
import os | |
##import numpy as np | |
greetings = ['hello','hi','whats up','sup','yo','hey'] | |
## setting intents for discord bot# | |
intents = discord.Intents.default() | |
intents.message_content = True | |
## setting bot prefix# | |
bot = commands.Bot(command_prefix='!',intents=intents, case_insensitive=True, help_command=None) | |
@bot.event | |
async def on_ready(): | |
## logging bot is ready to use in console | |
print('Bot is now online!') | |
## setting bot status message | |
await bot.change_presence(activity=discord.Game(name=f'Hi! I am {bot.user.name}. Please use ! to interact with me!')) | |
@bot.event | |
async def on_message(message): | |
## wait to see if its a command first | |
await bot.process_commands(message) | |
## on message event - setting so the bot doesnt reply to its own message | |
if message.author == bot.user: | |
return | |
if message.content in greetings: | |
channel = message.channel | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Hey there') | |
## chatbot logic needs to be somwehre else later | |
## users sends a message | |
## run a check if message had 'most played' in it | |
## sends a question back about summoner | |
## waits for reply and uses that so bring most played data | |
if 'most played' in message.content: | |
channel = message.channel | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Whats your summoner name?') | |
def check(m): | |
return message.content | |
msg = await bot.wait_for('message', check=check) | |
## embed results | |
champions = idk.get_top5(msg.content) | |
top5 = discord.Embed(title=f'{msg.content}\'s 5 most played champions:') | |
pfp = f'http://ddragon.leagueoflegends.com/cdn/12.20.1/img/champion/{champions[0]}.png' | |
top5.set_thumbnail(url=f'{pfp}') | |
for champion in champions: | |
emoji = f'\:{champion}_0:' | |
top5.add_field(name=f'**{champion}**',value=f'\:{champion}_0:',inline=False) | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send(embed = top5) | |
## users sends a message | |
## run a check if message had 'most played' in it | |
## sends a question back about summoner | |
## waits for reply and uses that so bring most played data | |
if 'stats' in message.content: | |
channel = message.channel | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Whats your summoner name?') | |
def check(m): | |
return message.content | |
msg = await bot.wait_for('message', check=check) | |
## embed results | |
ranked_stats = idk.get_summoner_stats(msg.content) | |
stats = discord.Embed(title=f'{msg.content}\'s ranked stats') | |
sender = message.author | |
pfp = sender.display_avatar | |
stats.set_thumbnail(url='https://i.postimg.cc/SsX4nyp3/GOLD.png') | |
stats.add_field(name=f'**Rank**',value=f'{ranked_stats[0]}') | |
stats.add_field(name=f'**Divison**',value=f'{ranked_stats[1]}') | |
stats.add_field(name=f'**LP**',value=f'{ranked_stats[2]}') | |
stats.add_field(name=f'**Winrate**',value=f'{ranked_stats[3]}') | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send(embed = stats) | |
if 'champion mastery' in message.content: | |
channel = message.channel | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Whats your summoner name?') | |
def check(m): | |
return message.content | |
message = await bot.wait_for('message',check = check) | |
summoner_name = message.content | |
print(summoner_name) | |
await channel.send('What champion do you want to find the mastery for?') | |
def check(m): | |
return message.content | |
message = await bot.wait_for('message', check = check) | |
champion_name = message.content | |
print(champion_name) | |
summoner_id = idk.get_summoner_id(summoner_name, False) | |
champion_id = idk.get_champion_id_by_name(champion_name) | |
if champion_id == "Wrong name": | |
await channel.send("This champion name is incorrect. Please make sure you capitalize the first letter and try again.") | |
else: | |
mastery_stats = idk.getChampionMastery(summoner_id, champion_id) | |
print("working") | |
stats = discord.Embed(title=f'{summoner_name}\'s mastery information for {champion_name}') | |
championLevel = mastery_stats['championLevel'] | |
championPoints = mastery_stats['championPoints'] | |
championPointsSinceLastLevel = mastery_stats['championPointsSinceLastLevel'] | |
championPointsUntilNextLevel = mastery_stats['championPointsUntilNextLevel'] | |
stats.add_field(name=f'**Champion Level**', value=f'{championLevel}') | |
stats.add_field(name=f'**Champion Points**', value=f'{championPoints}') | |
stats.add_field(name=f'**Champion Points Since Last Level**', value=f'{championPointsSinceLastLevel}') | |
stats.add_field(name=f'**Champion Points Until Next Level**', value=f'{championPointsUntilNextLevel}') | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send(embed = stats) | |
if 'match history' in message.content: | |
channel = message.channel | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Whats your summoner name?') | |
def check(m): | |
return message.content | |
msg = await bot.wait_for('message', check=check) | |
match_history = idk.get_winrate(msg.content) | |
history = discord.Embed(title=f'{msg.content}\'s match history') | |
sender = message.author | |
pfp = sender.display_avatar | |
for keys in match_history.keys(): | |
history.add_field(name=f'**{keys}**',value=f'Played:{match_history[keys][0]} Wins:{match_history[keys][1]} Losses:{match_history[keys][2]}') | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send(embed = history) | |
#sean | |
if 'puuid' in message.content: | |
channel = message.channel | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Whats your summoner name?') | |
def check(m): | |
return message.content | |
msg = await bot.wait_for('message', check=check) | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Whats your region?') | |
def check(m): | |
return message.content | |
msg2 = await bot.wait_for('message', check=check) | |
await channel.send(idk.get_player_puuid(msg.content, msg2.content)) | |
if 'game' in message.content: | |
channel = message.channel | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('which one of your recent games would you like the stats for?') | |
def check(m): | |
return message.content | |
game = await bot.wait_for('message', check=check) | |
gamenum = int(game.content) | |
async with channel.typing(): | |
await asyncio.sleep(1) | |
await channel.send('Whats your name?') | |
def check(m): | |
return message.content | |
name = await bot.wait_for('message', check=check) | |
await channel.send(idk.display_match_stats(gamenum)) | |
if 'kills' in message.content: | |
idk.displayKills() | |
channel = message.channel | |
await channel.send(file =discord.File("kills.png")) | |
if 'deaths' in message.content: | |
idk.displayDeaths() | |
channel = message.channel | |
await channel.send(file =discord.File("deaths.png")) | |
if 'assists' in message.content: | |
idk.displayAssists() | |
channel = message.channel | |
await channel.send(file =discord.File("assists.png")) | |
bot.run(secretkeys.discord_bot_key) |