Skip to content
Permalink
Browse files
Banned function now works
  • Loading branch information
lycette2 committed Nov 19, 2020
2 parents 7ddfb63 + 5909012 commit 8f4c1a70acfb7fbd383012d31322bfc8ba306eb3
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 17 deletions.
BIN +0 Bytes (100%) .vs/slnx.sqlite
Binary file not shown.
@@ -6,10 +6,13 @@ import random
import discord
import steam
import requests
#import JSON
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 *

tempButPermIDArraySteam = []
tempButPermIDArrayDiscord = []

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
@@ -20,9 +23,10 @@ client = discord.Client()
api = WebAPI(key=steamApiKey)

#==================DEFINITIONS GO HERE==================
#==================Emily=Function=Start=================

def fetchSteamID(): #this is a stub to replace
return 76561198108012956 #my steamID, don't abuse pls - Emily
#def fetchSteamID(): #this is a stub to replace
#return 76561198108012956 #my steamID, don't abuse pls - Emily

def fetchGameID(): #this is a stub to replace
return 582010 #this is monster hunter world
@@ -68,7 +72,43 @@ def steamAchievementPercentages(steamID, gameID): #Emily
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)

#print (steamAchievementPercentages("76561198108012956", "582010"))

#================Emily=Function=End============================================

#================BenHB=Function=Start==========================================

#SteamID START
def findSteamID(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():
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.steam.steamid.is_valid():
if formattedSteamID not in tempButPermIDArraySteam and discordID not in tempButPermIDArrayDiscord :
tempButPermIDArrayDiscord.append(discordID)
tempButPermIDArraySteam.append(formattedSteamID)
sharedRelationshipIndex = tempButPermIDArrayDiscord.index(discordID)
return("I have your ID now. Thanks!!! \n Here is the ID that was registered: \n" + tempButPermIDArraySteam[sharedRelationshipIndex])
elif(formattedSteamID in tempButPermIDArraySteam and discordID not in tempButPermIDArrayDiscord) or (formattedSteamID not in tempButPermIDArraySteam and discordID in tempButPermIDArrayDiscord):
sharedRelationshipIndex = tempButPermIDArrayDiscord.index(discordID)
return("This xor is working perfectly fine and will have code implemented shortly-ish... \n Here is the ID that was registered: \n" + tempButPermIDArraySteam[sharedRelationshipIndex])
else:
sharedRelationshipIndex = tempButPermIDArrayDiscord.index(discordID)
return("I already have your ID. Thanks anyway though!!! \n Here is the ID that was registered: \n" + tempButPermIDArraySteam[sharedRelationshipIndex])
else:
return("To link your steam requires a SteamID64 which can be found at:")
#SteamID END



@@ -136,32 +176,30 @@ async def on_message(message): #checks for a message
achievementWords = ["achievement", "steam" ] # This is to call the steamAchievementPercentages() function
#if [entry for entry in achievementWords if(entry in message.content.lower())]:
if "steam" and [entry for entry in achievementWords if(entry in message.content.lower())]:
await message.channel.send(steamAchievementPercentages(fetchSteamID(), fetchGameID()))
await message.channel.send(steamAchievementPercentages(findSteamID(), fetchGameID()))
if "steam" and "banned" in message.content.lower():
await message.channel.send(isUserBanned(fetchSteamID()))

# ================================================

# ================ Masud did this ================

tickEmoji = "\u2705" # unicode for the tick Emoji
crossEmoji = "\u274C" # unicode for the cross Emoji

if "salt " == (message.content.lower())[:5]: # checks if the input matches "salt "
communityName = (message.content)[5:] # saves the rest of the input as communityName

await message.add_reaction("🆗") # devops work item 35

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
await message.channel.send(f'The community: {communityName} already has a poll active. Poll ID:{pollID}.') # message to discord
else: # and if there is not an active poll already...
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
# print(f'[BOT DEBUG] {communityName} added to list of polls') # print to console for debugging only
polls[poll.id] = communityName.upper() # save the pollID and communityName together
print(polls) # print list of polls active for debugging only
await poll.add_reaction(tickEmoji) # add the tick emoji for the poll
await poll.add_reaction(crossEmoji) # add the cross emoji for the poll
# 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 "
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 communityName.upper() not in polls.values(): # checks if the poll does not exist already
@@ -173,14 +211,57 @@ async def on_message(message): #checks for a message
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

countEmbed = discord.Embed() # Discord embed object
countDesc = "" # description of countEmbed object
countEmbed.title = f"Is the community {communityName} salty or supportive?" # title of countEmbed object. DevOps work item 32

tickCount = 0
crossCount = 0

for emj in pollReactions: # for each emoji in the reactions object
emojiCount = emj.count - 1 # remove 1 vote, which was from the bot.
if emojiCount == 1: # message to discord accordingly
await message.channel.send(f'{emj.emoji} : {emojiCount} vote')
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:
await message.channel.send(f'{emj.emoji} : {emojiCount} votes')
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 equally 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."

# add the description to the embed and message it to the channel.
countEmbed.description = countDesc # add embed description to embed
await message.channel.send(embed=countEmbed) # send the embed to the channel the message is in

# ================ up to about here ================
#BenHB Start
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():
messageInfo = findSteamID(message.content, message.author.id)
await message.channel.send(messageInfo)


#GameID START ======= WIP
#async def gameIDRetrieve(gameName):
#sharedIDIndex = tempButPermIDArrayDiscord[message.author.id]
#steamId = tempButPermIDArraySteam[sharedIDIndex]
#response = await fetch(`https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=${steamApiKey}&steamid=${profileId}&format=json`);
#json = await response.json();
#userGameIDs = json.response.games.map(o=>o.appid);
#console.log(JSON.stringify(userGameIDs));
#BenHB 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

0 comments on commit 8f4c1a7

Please sign in to comment.