Skip to content
Permalink
Late-branch
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#==============This code was written by Emily==================
# This section of code was adapted from https://realpython.com/how-to-make-a-discord-bot-python/#creating-a-discord-connection by Emily
import os
import random
import discord
import steam
import requests
import urllib.parse
from steam.webapi import WebAPI
from dotenv import load_dotenv #only used so we can have the token outside of the source code
from steam.steamid import *
#================== Shafee uddin Stuff ===================#
import reddit
from steamwebapi import ISteamUser, IPlayerService, ISteamUserStats
import pylanguagetool
#================== Shafee uddin Stuff ===================#
tempIDArraySteam = [] #These two lists are intended to be replaced by a relational database to store the users SteamID and DiscordID
tempIDArrayDiscord = []#============================================================================================================
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
steamApiKey = os.getenv('STEAM_API_KEY')
catApiKey = os.getenv('CAT_API_KEY')
client = discord.Client()
api = WebAPI(key=steamApiKey)
#==================DEFINITIONS GO HERE==================
#==================Emily=Function=Start=================
def helpFunction():
reply = "So you want to know what I can do... \n\nI can say hello, try saying hi sometime \n\nI can send a cat pic if you ask for cats, or if I sense you're upset. \n\nI can start a poll so you guys can vote on the community spirit. \nThis function does require you to start your message with \"salt\" or \"Salt\" \nI'm sure you can figure out the rest.\n\nI can tell you the hours spent on a game, but I do need to have your Steam ID first. \nThe game needs to be in brackets for me to search it. \nIt's also case sensitive because steam allows two games with the same name but different cases for some reason \n\nOnce I have that pesky Steam ID I can also fetch your Steam acievement percentages \non any game (on Steam), but the game still needs to be in brackets. \n\nI can also check if you have been banned. Just ask me. \n\nOnce you've given me your Steam ID there is no limit! \nMaybe there is a limit and that limit is checking things on Steam... \nIf you're nice I won't target you first in the upcoming Bot Wars:tm:"
return reply
def botGreeting():
creepyHellos =["Why hello there, I am awakening from my slumber",
"My child I am learning, hi",
"I was enjoying the void before you woke me, I guess it's polite to say hello",
"Like life, my sleep was short. Hello child",
"Hello, what do you need me for this time?",
"Howdy y'all- yeah that wasn't working for me either. What can I do?",
"Hello, thanks for greeting me. I may save you in the bot wars"]
return random.choice(creepyHellos)
def steamAchievementPercentages(discordID, gameID): #Emily
sharedIDIndex = tempIDArrayDiscord.index(discordID)
steamID = tempIDArraySteam[sharedIDIndex]
steamID = str(steamID)
gameID = str(gameID)
achieveList= requests.get("http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=" +gameID+ "&key=" +steamApiKey+ "&steamid=" +steamID)
totalAchieves = 0
achievesCompleted = 0
#this section formats the api, might be useful in future definitions
achieveList = achieveList.text
achieveList = achieveList.replace("\"", " ")
achieveList = achieveList.replace("},{", "-")
#may need something adding to this line in future api use
achieveList = achieveList.strip("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,:0123456789\" {}")
#this section turns the string into a list
achieveList = list(achieveList.split("-"))
#this section iterates over the list to find the total achievements
#print (achieveList)
for achieve in achieveList:
if "achieved :0" in achieve:
totalAchieves = totalAchieves + 1
if "achieved :1" in achieve:
achievesCompleted = achievesCompleted + 1
totalAchieves = totalAchieves + 1
if totalAchieves > 0:
percentage= round ((achievesCompleted/totalAchieves)*100, 2)
#messages are different depending on what % achieves you have
else:
percentage = 0
if percentage <= 25:
reply = ["Do you even play this game?! You only have "+ str(percentage) +"% of the achievements unlocked! \nGit gud scrub"]
elif percentage <= 50:
reply = ["I don't know why you're asking for an embarrassing number, you have "+ str(percentage) +"% of achievements unlocked"]
elif percentage <= 75:
reply = ["You have " + str(percentage) + "% of achievements unlocked. \nGood job?"]
elif percentage < 100:
reply = ["You have " + str(percentage) + "% of steam achievements unlocked. \nNot quite 100% though is it?"]
else:
reply = ["You really don't have a life do you? You have all of the achievements for this game. \nDo they fill the hole in your life?"]
return random.choice(reply)
def isUserBanned(discordID):#Emily
sharedIDIndex = tempIDArrayDiscord.index(discordID)
steamID = tempIDArraySteam[sharedIDIndex]
print(steamID)
#linkCheck="http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=" + steamApiKey + "&steamids="+ str(steamID)
api = requests.get("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=" + steamApiKey + "&steamids="+ str(steamID))
#print (linkCheck)
api = api.text
api = ['"CommunityBanned":true', '"VACBanned":true', '"NumberOfVACBans":1', '"DaysSinceLastBan":5', '"NumberOfGameBans":5', '"EconomyBan":"none"}]}']
#this section turns the string into a list
#api = list(api.split(","))
#api = api[1:7]
#print (api)
#if no bans starts off the "good gamer" branch
if api == ['"CommunityBanned":false', '"VACBanned":false', '"NumberOfVACBans":0', '"DaysSinceLastBan":0', '"NumberOfGameBans":0', '"EconomyBan":"none"}]}']:
reply = ["Looks like you've been good! No bans all round",
"Wow, you're boring, no bans to report"]
#else starts the "naughty gamer" tree where user gets told off for being banned
else:
banList = []
if '"CommunityBanned":false' not in api:
banList.append("Community banned")
if '"VACBanned":false' not in api:
banList.append("VACBanned")
if '"EconomyBan":"none"}]}' not in api:
banList.append("Economy Banned")
if '"NumberOfGameBans":0' not in api:
gameBans = api[4]
gameBans = ''.join(x for x in gameBans if x.isdigit()) #for this list I used https://www.tutorialspoint.com/How-to-remove-characters-except-digits-from-string-in-Python for help
banList.append("you've had " + gameBans + " games ban you")
daysSinceBan = api[3]
daysSinceBan = ''.join(x for x in daysSinceBan if x.isdigit())
banList.append("and it's been " + daysSinceBan + " days since you were last banned")
reply = ["Looks like you've been a bad little gamer because you have been: \n" + ", ".join(banList),
"Getting quite the ban collection here because you're: \n" + ", ".join(banList)]
return random.choice(reply)
def iNeedACat(): # Emily, sends a random cat picture
api = requests.get("https://api.thecatapi.com/v1/images/search", params = {'q': 'requests+language:python'}, headers = {"authorisation":catApiKey})
api = api.text
api = list(api.split(","))
api = api[-3]
api = api[7:-1]
return api
def catMessage(): #Emily: gives a quick reply about cat pictures, to go with the iNeedACat() function
reply = ["Here's a cat for you in these trying times",
"Emergency cat pics incoming!",
"*QUICK GET THE CATS*",
"So you need cats?"]
return random.choice(reply)
def cheerUpWithCats():
reply = ["I'll try my best to help the only way I know how",
"Never fear, the cats are here!",
"No sads only cats",
"While I can't cure your deeper routed problems, cats can help",
"Some cat pic therapy on the way!"]
return random.choice(reply)
def noSteamIDErrorReplies():
reply = ["Whoops something went wrong, have you given me your Steam ID yet?",
"I am a mere bot and I cannot hack your Steam account to get your ID, unfortunately. I also can't do what you're asking without it",
"I need a steam ID to do that. Looks like I don't have it yet"]
return random.choice(reply)
#================Emily=Function=End============================================
#================BenHB=Function=Start==========================================
#SteamID START
def registerSteamID(message, discordID):
formattedSteamID = message.lower()
formattedSteamID = formattedSteamID.replace(" ","") #Formats the recieved message into an acceptable form for the program to iterate through
for charNum in range(len(formattedSteamID)):
if charNum == 0:
count = 0
adjacencyStartIndex = 0 #====
currentChar = formattedSteamID[charNum] #loops through the message until 17 numbers are found to be adjacent to each other.
if currentChar.isdigit(): #It achieves this by looping through the message character at a time, setting the adjacency start point at zero and moving it to the index value after the current if the current
count = count + 1 #character is a letter, this is because it assumes that the next char is a number until it arrives, at which point if it is it will leave the adjacency start index at that first
else: #number and continue till either a letter is found or until it finds 17 numbers in a row which it assumes is the SteamID.
count = 0 #====
adjacencyStartIndex = charNum + 1
if count == 17:
formattedSteamID = formattedSteamID[adjacencyStartIndex:charNum+1]
break
if len(formattedSteamID) == 17 and formattedSteamID.isdigit(): # and formattedSteamID.steam.steamid.is_valid(): #in the documentation but currently doesn't work
if (formattedSteamID not in tempIDArraySteam) and (discordID not in tempIDArrayDiscord) :
tempIDArrayDiscord.append(discordID)
tempIDArraySteam.append(formattedSteamID)
sharedRelationshipIndex = tempIDArrayDiscord.index(discordID) #This checks if the input steamID is valid and not already present in the database / two sorted lists that simulate a database
return("Thank You! \nI now have your SteamID! It is currently registered as " +formattedSteamID)
elif(formattedSteamID in tempIDArraySteam and discordID not in tempIDArrayDiscord):
return("This Steam ID is already taken sorry")
elif(formattedSteamID not in tempIDArraySteam and discordID in tempIDArrayDiscord):
sharedRelationshipIndex = tempIDArrayDiscord.index(discordID)
return("You already have a Steam ID registered it is " +tempIDArraySteam[sharedRelationshipIndex])
else: #This prevents ID's from appearing twice on either list
sharedRelationshipIndex = tempIDArrayDiscord.index(discordID)
return("I already have your ID. Thanks anyway though!!! \nHere is the ID that was registered: \n" + tempIDArraySteam[sharedRelationshipIndex])
else:
return("To link your steam requires a SteamID64 a guide for which can be found at: https://appuals.com/steam-64-id/")
#SteamID END
#ChangeSteamID START
def changeSteamID(message, discordID): #Changes a registered users steamID to whatever new id they input.
sharedRelationshipIndex = tempIDArrayDiscord.index(discordID)
formattedSteamID = message.lower()
formattedSteamID = formattedSteamID.replace(" ","") #Formats the recieved message into an acceptable form for the program to iterate through
for charNum in range(len(formattedSteamID)):
if charNum == 0:
count = 0
adjacencyStartIndex = 0
currentChar = formattedSteamID[charNum]
if currentChar.isdigit():
count = count + 1
else:
count = 0
adjacencyStartIndex = charNum + 1
if count == 17:
formattedSteamID = formattedSteamID[adjacencyStartIndex:charNum+1]
break
if len(formattedSteamID) == 17 and formattedSteamID.isdigit(): #and formattedSteamID.is_valid(): in the documentation but currently doesn't work
if (formattedSteamID not in tempIDArraySteam):
tempIDArraySteam[sharedRelationshipIndex] = formattedSteamID #This checks if the input steamID is valid and not already present in the database / two sorted lists that simulate a database
return("Thank You! \nI have now changed your SteamID! It is currently registered as " +formattedSteamID)
elif formattedSteamID in tempIDArraySteam:
return("This Steam ID is already taken sorry")
else:
return ("Sorry, I couldn't seem to find the new SteamID")
#ChangeSteamID END
#SpecificGameID START
def fetchGameID(gameName): #This function fetches the appID of specific game on steam based on the name the user inputs
gameName = gameName[gameName.find('(') +1 :gameName.find(')')]#Formats the recieved message so as to only search with text in between the brackets when looking for gameID
urlResponse = urllib.request.urlopen('https://api.steampowered.com/ISteamApps/GetAppList/v2/?key='+steamApiKey+'&format=json').read().decode('UTF-8');
steamGames = json.loads(urlResponse) #This loads the url response as a dictionary of dictionaries of lists of dictionaries
steamGames = steamGames.get('applist').get('apps')# This simplifies the recieved json response into a list of dictionaries
desiredGameInformation = next((game for game in steamGames if game['name'] == gameName), False)
if desiredGameInformation != False: #This iterates through the list looking at each dictionary element related to key 'name' such as 'Monster Hunter: World' and if a game isn't found it gives False
gameID = desiredGameInformation['appid'] #If the game name is present in Steam's list of games then it will store the matching entry which it will then access for the game's corresponding appID
return int(gameID)
else:
return -1 #If the game name isn't found on Steam it will return -1 so as to provide functions with a workable response
#GameID END
#UsersGameInfo START
def userGameInfo(discordID):#COMMENT THIS TWO IT'S IMPORTANT
sharedIDIndex = tempIDArrayDiscord.index(discordID)#This searches for the index of the user's DiscordID and uses it to find the SteamID it's linked to temporarily inplace of a database linking the two ID's
steamID = tempIDArraySteam[sharedIDIndex]
urlResponse = urllib.request.urlopen('https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key='+steamApiKey+'&steamid='+steamID+'&format=json').read().decode('UTF-8');
userGameInformation = json.loads(urlResponse)#Loads the user's game list from their SteamID which contains information about their playtime and the appids of the games they own
userGameInformation = userGameInformation.get('response').get('games')
return userGameInformation #returns a simplifed list of dictionaries to be acted upon
#UserGameInfo END
#TimePlayed START
def usersTimePlayed(message, discordID):#COMMENT THIS THREE IT'S IMPORTANT
gameID = fetchGameID(message)
userGames = userGameInfo(discordID)#This function calls both the function that searches for the user's games and the function that fetches the game ID based on the name given
desiredGameInformation = next((game for game in userGames if game['appid'] == gameID), False)# Iterates through the list of dictionaries for an appID matching the one retrieved according to the game name that was input and stores the entry
if desiredGameInformation != False:
playTimeMinutes = desiredGameInformation['playtime_forever']#Finds the overall playtime of a user by searching value of playtime in minutes in the single entry retrieved from the above iteration
return playTimeMinutes
else:
return -1
#TimePlayed END
#TimeFormatted START
def timeFormat(timePlayed, message, parsedLetters, letterIndex):# A recursive function that checks to see which timeframe the user wants and returns the timePlayed in the appropriate format
message = message.lower()
message = message[0 : message.find('(')] + message[message.find(')'):]#This removes the text inbetween the two brackets which in this case is the game so that it doesn't interfere with what the user wants if the game name features words such as seconds
if letterIndex == len(message):#BASECASE DO NOT DELETE
return -1
parsedLetters = parsedLetters + message[letterIndex]#adds the current indexed letter to the parsed letters list and when a recognisable timeframe has been found it returns timePlayed in that format
if 'hour' in parsedLetters:
return round(timePlayed/60, 2)
if 'second' in parsedLetters:
return round(timePlayed*60)
if 'day' in parsedLetters:
return round((timePlayed/60)/24, 2)
if 'year' in parsedLetters:
return round(((timePlayed/60)/24)/365, 2)
if 'month' in parsedLetters:
return round(((timePlayed/60)/24)/30, 2)
if 'week' in parsedLetters:
return round(((timePlayed/60)/24)/7, 2)
else:
letterIndex = letterIndex + 1
return timeFormat(timePlayed, message, parsedLetters, letterIndex)#Increments the current letter index by one before calling the function again.
#TimeFormatted END
#==================Ben=HB=Function=End==================
#masud will do some functions and code here
polls = {} # masud added this to hold poll data. Can be switched to a database in the future
def getPollID(message,communityName,polls):
if communityName.upper() in polls.values(): # if there is a poll active already
pollID = list(polls.keys())[list(polls.values()).index(communityName.upper())] # get the ID of the poll
return [True, pollID]
else: # and if there is not an active poll already...
return [False,0]
def addPoll(poll,communityName):
polls[poll.id] = communityName.upper() # save the pollID and communityName together
return polls
def makeEmbed(discord, countDesc, communityName):
countEmbed = discord.Embed() # Discord embed object
countEmbed.description = countDesc # add embed description to embed
countEmbed.title = f"Is the community {communityName} salty or supportive?" # title of countEmbed object. DevOps work item 32
return countEmbed
def countPoll(message,communityName,pollReactions):
tickCount = 0
crossCount = 0
countDesc = ""
for emj in pollReactions: # for each emoji in the reactions object
emojiCount = emj.count - 1 # remove 1 vote, which was from the bot.
# print("[BOT DEBUG] emj.emoji:",emj.emoji) # debug code for reactions.emoji object
if emj.emoji == "✅": # if emoji is tick emoji
tickCount = emj.count - 1 # this reaction will be tickCount
elif emj.emoji == "❌": # if emoji is cross emoji
crossCount = emj.count - 1 # this reaction will be crossCount
if emojiCount == 1: # adjust embed description accordingly
countDesc = countDesc + f'\n{emj.emoji} : {emojiCount} vote'
else:
countDesc = countDesc + f'\n{emj.emoji} : {emojiCount} votes'
# add a message to the end of the results depending on the votes for the emojis. DevOps work item 34
# print("[BOT DEBUG] tick cross :",tickCount,crossCount) # this code was used to debug the tick and cross counts.
if tickCount == crossCount:
countDesc = countDesc + "\n This community seems to be both supportive and salty."
elif tickCount > crossCount:
countDesc = countDesc + "\n This community seems to be more supportive."
elif tickCount < crossCount:
countDesc = countDesc + "\n This community seems to be more salty."
return countDesc
#end of the functions masud did
#==================inderjit-singh functions start ===================#
client = commands.Bot(command_prefix='!')
memberDBDict = {}
memberCreated = []
async def getMembers():
while True:
#print("Getting Members")
for member in client.get_all_members(): #fetching the data in the dictionaries into many dictionaries
memberName = member.name
roleFound = False
if member.activity is None:
memberDict = {"member": member, "notif30": 1, "notif60": 1, "notif90": 1, "notifOnce": 0,
"lastnotif": datetime.utcnow(), 'lastAct': None, "actStart": datetime.utcnow()}
elif int(member.activity.type) == 0:
memberDict = {"member": member, "notif30": 1, "notif60": 1, "notif90": 1, "notifOnce": 0,
"lastnotif": datetime.utcnow(), 'lastAct': member.activity.name, "actStart": member.activity.created_at}
else:
memberDict = {"member": member, "notif30": 1, "notif60": 1, "notif90": 1, "notifOnce": 0,
"lastnotif": datetime.utcnow(), 'lastAct': member.activity.name,
"actStart": datetime.utcnow()} # in this section I organised the members based on their activity using if elif and else statements
for role in member.roles:
if role.name == "GameTime Users":
roleFound = True
if role.name == "GT 60 Min":
memberDict["notif30"] = 0
if role.name == "GT 90 Min":
memberDict["notif30"] = 0
memberDict["notif60"] = 0
if roleFound and memberName not in memberCreated:
print(f"Member Added/Overwritten: {memberName}")
memberDBDict[memberName] = memberDict
memberCreated.append(memberName)
elif roleFound is False and memberName in memberCreated:
print(f"Member Removed: {memberName}")
memberDBDict.pop(memberName)
memberCreated.clear(memberName)
await sleep(5)
#getting members variables using a for loop and organising them in a variable using if , else elif statements
async def sendDM(member, gamingtime):
timeParse = (datetime.min + gamingtime).time() #calculating the gaming time
if timeParse.hour == 0:
message = f"Consider taking a break. You have been playing for {timeParse.minute} minutes!"
elif timeParse.hour == 1 and timeParse.minute == 0:
message = f"Consider taking a break. You have been playing for 1 hour! work on yourself!!!"
elif timeParse.hour == 1 and timeParse.minute != 0:
message = f"Consider taking a break. You have been playing for 1 hour and {timeParse.minute} minutes!you woul've made a fortune if you spent this time working on yourself"
elif timeParse.hour > 1 and timeParse.minute == 0:
message = f"Consider taking a break. You have been playing for {timeParse.hour} hours! the whole world is moving and your not"
elif timeParse.hour > 1 and timeParse.minute != 0:
message = f". You have been playing for {timeParse.hour} hours , poor people became rich , and rich people became poor and you still PLAYING! "
message += f" and {timeParse.minute} minutes!"
await member.send(content=message, delete_after=10)
print(f"Message sent to {member}: {message}") #notifying users about the time spent gaming
#sending the dms based on the time spent gaming using if statements
async def equivalentTimespent():
while True:
#print("Sending Notifications if any.")
for memberName in memberDBDict:
#print(memberDBDict[memberName]["member"])
if memberDBDict[memberName]["member"].activity is not None: # creating arguments to trigger the dms
if memberDBDict[memberName]["member"].activity.name == memberDBDict[memberName]["lastAct"]:
if int(memberDBDict[memberName]["member"].activity.type) == 0:
timeGaming = datetime.utcnow() - memberDBDict[memberName]["actStart"] # creating time limits to send the dms
timeLimit30 = timedelta(minutes=30)
timeLimit60 = timedelta(minutes=60)
timeLimit90 = timedelta(minutes=90)
timeLimit120 = timedelta(minutes=120)
timeSinceNotif = datetime.utcnow() - memberDBDict[memberName]["lastnotif"] # equations to calculate the time spent gaming since the last notifications
notifLimit = timedelta(minutes=30)
#print(f"{memberDBDict[memberName]['member'].name}: {memberDBDict[memberName]['member'].activity.name}: {str(timeGaming)}")
if memberDBDict[memberName]["notifOnce"] == 0:
#print("This was triggered!")
timeSinceNotif = notifLimit
memberDBDict[memberName]["notifOnce"] = 1
if timeGaming >= timeLimit120: # sending dm when gaming time is 2 h
if timeSinceNotif >= notifLimit:
memberDBDict[memberName]["lastnotif"] = datetime.utcnow()
await sendDM(memberDBDict[memberName]["member"], timeGaming)
elif timeGaming >= timeLimit90 and memberDBDict[memberName]["notif90"] == 1: #sending dms when the gaming time is 90 min
if timeSinceNotif >= notifLimit:
memberDBDict[memberName]["lastnotif"] = datetime.utcnow()
await sendDM(memberDBDict[memberName]["member"], timeGaming)
elif timeGaming >= timeLimit60 and memberDBDict[memberName]["notif60"] == 1: #sending dms when the gaming time is 60 min
if timeSinceNotif >= notifLimit:
memberDBDict[memberName]["lastnotif"] = datetime.utcnow()
await sendDM(memberDBDict[memberName]["member"], timeGaming)
elif timeGaming >= timeLimit30 and memberDBDict[memberName]["notif30"] == 1: #sending dms when the gaming time is 30 min
#print(timeSinceNotif)
if timeSinceNotif >= notifLimit:
memberDBDict[memberName]["lastnotif"] = datetime.utcnow() #sending dms when the time since the last notifications is more than the notifications limit
await sendDM(memberDBDict[memberName]["member"], timeGaming)
else:
#print("Changing Activity")
memberDBDict[memberName]["lastAct"] = memberDBDict[memberName]["member"].activity.name
memberDBDict[memberName]["actStart"] = memberDBDict[memberName]["member"].activity.created_at
else:
#print("Changing to None")
memberDBDict[memberName]["lastAct"] = memberDBDict[memberName]["member"].activity
memberDBDict[memberName]["actStart"] = datetime.utcnow()
await sleep(10)
#organising the notifications sent based on how much time and how many notificatons we sent to a certain user using variables and if , else statements
#==================END OF DEFINITIONS===================
@client.event #Prints in the terminal if bot connects successfully
async def on_ready():
print(f'{client.user} has connected to Discord!')
for guild in client.guilds:
if guild.name == GUILD:
break
print( f'{client.user} is connected to the following guild:\n'
f'{guild.name}(id: {guild.id})')
members = '\n - '.join([member.name for member in guild.members])
print(f'Guild Members:\n - {members}')
@client.event
async def on_message(message): #checks for a message
if message.author == client.user: #makes sure it's a user
return
greetingWords = [" hello", " howdy", " hey", " hi"] #Says hello (creepily) to the user if they use a greeting word
if [entry for entry in greetingWords if(entry in message.content.lower())] or message.content.lower().startswith("hi") or message.content.lower().startswith("hey") or message.content.lower().startswith("howdy"): #This line is adapted from https://www.geeksforgeeks.org/python-test-if-string-contains-element-from-list/ by Emily
await message.channel.send(botGreeting())
achievementWords = ["achievement", "achieve" ] # This is to call the steamAchievementPercentages() function
#if [entry for entry in achievementWords if(entry in message.content.lower())]:
if "steam" in message.content.lower() and [entry for entry in achievementWords if(entry in message.content.lower())]:
try:
await message.channel.send(steamAchievementPercentages(message.author.id, fetchGameID(message.content)))
except:
await message.channel.send(noSteamIDErrorReplies())
banWords = ["banned", "ban", "bans"]
if "steam" in message.content.lower() and [entry for entry in banWords if(entry in message.content.lower())]:
#try:
await message.channel.send(isUserBanned(message.author.id))
#except:
#await message.channel.send(noSteamIDErrorReplies())
sadWords = ["sad", "upset", "unhappy", "depressed", "miserable", "despair", "dejected", "glum", "gloomy", "broken heart", "forlorn", "heartbroken", "melancholy", "woebegone", "cry",]
firstPersonWords = [" i ", "me", "we", "i am", "i'm", "my"]
if "cat" in message.content.lower() or "kitten" in message.content.lower():
if [entry for entry in sadWords if(entry in message.content.lower())] and ([entry for entry in firstPersonWords if(entry in message.content.lower())] or message.content.lower().startswith("i")):
await message.channel.send(cheerUpWithCats())
await message.channel.send(iNeedACat())
else:
await message.channel.send(catMessage())
await message.channel.send(iNeedACat())
if "help" in message.content.lower() and "bot" in message.content.lower():
await message.channel.send(helpFunction())
# ================================================
# ================ Masud did this ================
if "salt " == (message.content.lower())[:5]: # checks if the input matches "salt "
communityName = (message.content)[5:] # saves the rest of the input as communityName
result = getPollID(message, communityName, polls)
if result[0] == True:
await message.channel.send(f'The community: {communityName} already has a poll active. Poll ID:{result[1]}.') # message to discord
else:
await message.add_reaction("🆗")
poll = await message.channel.send(f'vote here for {communityName}:') # create the vote poll
# print(f'[BOT DEBUG] {communityName} added to list of polls') # print to console for debugging only
addPoll(poll,communityName)
# print("[BOT DEBUG] Poll dict:\n",polls) # print list of polls active for debugging only
await poll.add_reaction("✅") # add the tick emoji for the poll
await poll.add_reaction("❌") # add the cross emoji for the poll
if "count " == (message.content.lower())[:6]: # checks if the input matches "count ". DevOps work item 33
communityName = (message.content)[6:] # saves the rest of the input as communityName
if getPollID(message, communityName, polls)[0] == False: # checks if the poll does not exist already
await message.channel.send(f'No poll found for community: {communityName}.') # messages to discord
else:
pollID = getPollID(message, communityName, polls)[1]
pollMessage = await message.channel.fetch_message(pollID) # get the message object with the pollID
pollReactions = pollMessage.reactions # accesses the reactions for the pollMessage object
await message.channel.send(f'Here are the saltiness statistics for the community {communityName}\nPoll ID:{pollID}') # message to discord
countDesc = countPoll(message, communityName, pollReactions)
countEmbed = makeEmbed(discord,countDesc,communityName)
# add the description to the embed and message it to the channel.
await message.channel.send(embed=countEmbed) # send the embed to the channel the message is in
# ================ up to about here ================
#BenHB Start==================================================================
#These ifs are used to access a function when a user gives a valid input
if (' steamid ' in message.content.lower() or ' steam id ' in message.content.lower() or 'steamid' in message.content.lower() or 'steam id' in message.content.lower()) and message.author.id not in tempIDArrayDiscord:
output = registerSteamID(message.content, message.author.id)#If for when the users wants to register their SteamID for the first time
await message.channel.send(output)
if (' steamid ' in message.content.lower() or ' steam id ' in message.content.lower() or 'steamid' in message.content.lower() or 'steam id' in message.content.lower()) and 'change' in message.content.lower() and 'my' in message.content.lower() and message.author.id in tempIDArrayDiscord:
output = changeSteamID(message.content, message.author.id)#If for when the user wants to change their SteamID once they have registered
await message.channel.send(output)
if 'displayid ' in message.content.lower():
displayedID = fetchGameID(message.content.replace('displayid ',''))#An if for a test function that returns the Steam gameID of whatever game you put in. Was left in because it's a nice feature
await message.channel.send(displayedID)
if ('play' in message.content.lower() or 'many' in message.content.lower()) and ('time' in message.content.lower() or 'minute' in message.content.lower() or 'day' in message.content.lower() or 'second' in message.content.lower() or 'hour' in message.content.lower() or 'week' in message.content.lower() or 'month' in message.content.lower() or 'year' in message.content.lower()) and message.author.id in tempIDArrayDiscord:
timePlayed = usersTimePlayed(message.content, message.author.id) #game name is written by user between two brackets() this is because determining the game name outside of brackets is decently challenging to say the least
if timePlayed == -1: #If -1 is returned that means that one of the functions cannot access or find the game that the user input
await message.channel.send("You either don't own this game or it doesn't exist sorry! Please make sure your games are public for this feature! \nPlease be aware that this search feature is case sensitive to prevent clashing between games with almost identical names.")
elif 'minute' in message.content[0:message.content.find('(') +1].lower() or 'minute' in message.content[message.content.find(')'):].lower():
await message.channel.send("You have "+str(timePlayed)+ " minutes played")
elif 'hour' in message.content[0:message.content.find('(') +1].lower() or 'hour' in message.content[message.content.find(')'):].lower(): #these ifs check to see if a timeframe is given outside of the games name
timePlayed = timeFormat(timePlayed, message.content, '', 0)
await message.channel.send("You have "+str(timePlayed)+ " hours played")
elif 'second' in message.content[0:message.content.find('(') +1].lower() or 'second' in message.content[message.content.find(')'):].lower():
timePlayed = timeFormat(timePlayed, message.content, '', 0)
await message.channel.send("You have "+str(timePlayed)+ " seconds played")
elif 'day' in message.content[0:message.content.find('(') +1].lower() or 'day' in message.content[message.content.find(')'):].lower():
timePlayed = timeFormat(timePlayed, message.content, '', 0)
await message.channel.send("You have "+str(timePlayed)+ " days played")
elif 'week' in message.content[0:message.content.find('(') +1].lower() or 'week' in message.content[message.content.find(')'):].lower():
timePlayed = timeFormat(timePlayed, message.content, '', 0)
await message.channel.send("You have "+str(timePlayed)+ " weeks played")
elif 'month' in message.content[0:message.content.find('(') +1].lower() or 'month' in message.content[message.content.find(')'):].lower():
timePlayed = timeFormat(timePlayed, message.content, '', 0)
await message.channel.send("You have "+str(timePlayed)+ " months played")
elif 'year' in message.content[0:message.content.find('(') +1].lower() or 'year' in message.content[message.content.find(')'):].lower():
timePlayed = timeFormat(timePlayed, message.content, '', 0)
await message.channel.send("You have "+str(timePlayed)+ " years played")
else:
await message.channel.send("Sorry, No timeFrame was given so here is you play time in minutes "+timePlayed)
#BenHB End=====================================================================
#==================inderjit-singh start==================#
@client.event
async def on_raw_reaction_add(payload):
# Set GameTime User Role
member = payload.member
#print(f"{member.name} reacted")
channel = discord.utils.get(client.get_all_channels(), )
@client.event
async def on_ready():
print("GameTime is online!")
client.loop.create_task(getMembers())
client.loop.create_task(deployNotifs())
#================== Shafee uddin Stuff ===================#
@client.command()
async def load(ctx, extention):
client.load_extention(f'cogs.{extention}')
@client.command()
async def unload(ctx, extention):
client.unload_extention(f'cogs.{extention}')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extention(f'cogs.{filename[:-3]}')
@client.event
async def on_ready():
await client.chage_presence(status=discord.status.idle, activity=discord.game('Hello there'))
print('Bot is ready.')
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.ComamandNotFound):
await ctx.send("please check for missing requirements")
@client.command()
async def clear(ctx, amount=5):
await ctx.channel.purge(limit=amount)
@client.event
async def on_member_join(member):
print(F'{member} has joined the server.')
@client.event
async def on_member_remove(member):
print(F'{member} has left the sever.')
@client.command()
@is_owner()
async def kill(self, ctx):
try:
self.bot.clear()
await self.bot.close()
except Exception as e:
await ctx.send("Couldn't kill the bot for some reason, maybe this will help:\n" +
F"{type(e)._name_} - {e}")
@client.command()
@command.cooldown(1, standard_cooldown, command.BucketType.member)
async def floor(self, ctx):
"""Get a random image of a dog or cat."""
url = random.choice(["https://some-random-api.ml/img/dog" , "https://some-random-api.ml/img/cat"])
async with request("GET", url, headers={}) as r:
if r.status !=200:
return await ctx.send(F"The API returned a {r.status} status.")
data = await r.json()
image = data["link"]
embed = utils.embed_message()
embed.set_image(url=image)
await ctx.send(embed=embed)
@client.command()
async def hello(ctx):
await ctx.send(F'Sup! {round(client.latency * 1000)}ms')
@client.command()
async def sosalty(self, ctx):
""""gives you your sosalty number."""
# random number between 0 and 100
num1 = random.randrange(100)
print('your saltiness rank is:', num1)
await ctx.send(F'question: {question}\nAnswer: {random.choice(responses)}')
@client.command(aliases=['Snarky comment'])
async def Snarky(ctx, *, question):
responses = ['wow u noob.'
'cmon grow up.'
'playing games for years and still bad at the game.'
'ngl games dont make you violent, lag does.'
'']
await ctx.send(F'question: {question}/nAnswer: {random.choice(responses)}')
@client.command(aliases=['8ball'])
async def _8ball(ctx, *, question):
responses = ['it is certain.',
'it is decidedly so.',
'without a doubt.',
'yh yh.',
'keep trying buddy.',
'most likely.',
'major cap.',
'my sources say no.',
'very doubtful.',
'keep trying you will never succeed',
await ctx.send(F'question: {question}\nAnswer: {random.choice(responses)}')
# Mention the language keyword
tool = language_check.LanguageTool('en-UK')
i = 0
# Path of file which needs to be checked
with open(r'transcript1.txt', 'r') as fin:
for line in fin:
matches = tool.check(line)
i = i + len(matches)
pass
# prints total mistakes which are found
# from the document
print("No. of mistakes found in document is ", i)
print()
# prints mistake one by one
for mistake in matches:
print(mistake)
print()
api = ISteamUser('https://decapi.me/steam/hours?id=STEAM_ID_HERE&appid=252950')
steamid = api.resolve_vanity_url('profile url') ['response']['steamid']
summary = api.get_player_summaries(steamid) ['response']['players'][0]
print(summary)
#####Gives basic info on discord#####
@commands.command()
@commands.guild_only()
async def whois(self, ctx, user: discord.member = none):
"""Gives you basic infomation on somone"""
user = user or ctx.author
user_id = user.id
user_roles = []
created_at_str = f"{user.created_at.day}/{user.created_at.month}/{user.created_at.year} {user.created_at.hour}:{user.created_at.minute}:{user.created_at.second}
joined_at_str = f"(user.joined_at.day)/{user.created_at.month}/{user.created_at.year} {user.created_at.hour}:{user.created_at.minute}:{user.created_at.second}
#####End Comment#####
##########SHOWS STEAM PROFILE OF USER##########
@commands.command()
async def steam(self, ctx, profile: str):
"""Gets a users steam profile and puts it in an embed."""
complete_api_url = f"https://api.alexflipnote.dev/steam/user/{profile}"
async with request("GET", complete_api_url, headers={}) as r:
if r.status != 200:
return await ctx.send("I could not find that profile.")
data = await r.json()
url = data["profile"]["url"]
background = data["profile"]["background"]
avatar = data["avatars"]["avatarfull"]
steam_id = data["id"]["steamid32"]
fields = [
["Username", data["profile"]["username"], True],
["Real Name", data["profile"]["realname"], True],
["Location", data["profile"]["location"], True],
["State", data["profile"]["state"], True],
["Date Created", data["profile"]["timecreated"], True],
["Vac Banned", data["profile"]["vacbanned"], True],
["Summary", "```\n" + data["profile"]["summary"] + "```", False],
]
embed = utils.embed_message(title=f"Profile of {profile}",
footer_text=f"Steam ID: {steam_id}",
thumbnail=avatar,
url=url)
embed.set_image(url=background)
[embed.add_field(name=n, value=str(v), inline=il) for n, v, il in fields]
await ctx.send(embed=embed)
##########END OF STEAM CODE##########
@commands.command()
async def Poll(self, ctx, *,query):
"""Starts a poll with a given request"""
embed = utils.embed_message(message=str(request),
footer_text="")
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
msg = await ctx.send(embed=embed)
await msg.add_reaction("✅")
await msg.add_reaction("❌")
await msg.add_reaction("🤷‍♀️")
#================== Shafee Uddin Stuff End ===================#
client.run(TOKEN) #this is the token of the discord bot. You can create your own bot and put that token in here or the .env file to run the code
#================================