async def on_socket_raw_receive(payload): if (type(payload) is str): jsonload = json.loads(payload) if (jsonload["t"] == "MESSAGE_REACTION_ADD" and jsonload["d"]["user_id"] != client.user.id): activeGames = jsonIO.read("activeGames.json") gameReacts = jsonIO.read("gameReacts.json") msgID = (str(jsonload["d"]["message_id"])) origMsg = (str(jsonload["d"]["message_id"])) if (msgID in gameReacts): msgID = gameReacts[msgID] if (msgID in activeGames): if (activeGames[msgID]["type"] == "minesweeper"): await gameTypeMinesweeper(jsonload, activeGames, msgID, origMsg)
from discord.utils import get import os import sys import asyncio import pathlib import pickle import json from datetime import datetime import jsonIO import minesweeper client = discord.Client() emojiList = discord.Server.emojis options = jsonIO.read("options.json") @client.event async def on_ready(): print('----------------------') print('Logged in as: ' + client.user.name) print('ID: ' + client.user.id) print('----------------------') #code for reading messages @client.event async def on_message(message): if message.author.bot:
def __init__(self, path): f = os.open(path, os.O_RDONLY) str = os.read(f, 9999) os.close(f) self.d = jsonIO.read(str) pass
import sys import jsonIO f = open("/var/www/eHome/eHomeHeizungVals.json","r") str = f.read() f.close() obj = jsonIO.read(str[1:-1]) print obj[sys.argv[1]]
def genNewGame(message_id, row_id, col_id, act_id, size): #cells are saved as in activegames [flag,open,bomb,neighbors] try: gridSize = int(size) gridSize = min(gridMax, max(gridSize, gridMin)) except: gridSize = gridMin #random.randint(gridMin, gridMax) bombcount = math.floor(gridSize * math.log(gridSize, 7)) newGameGrid = [] for x in range(gridSize): newGameGrid.append([]) for y in range(gridSize): newGameGrid[x].append([False, False, False, 0]) bombs = [] while (len(bombs) < bombcount): newBomb = [ random.randint(0, gridSize - 1), random.randint(0, gridSize - 1) ] if ((newBomb in bombs) == False): bombs.append(newBomb) for b in bombs: newGameGrid[b[0]][b[1]][2] = True for y in range(gridSize): for x in range(gridSize): neighborCount = 0 neighbors = getNeighbors(x, y, gridSize) for n in neighbors: if (newGameGrid[n[0]][n[1]][2] == True): neighborCount += 1 newGameGrid[x][y][3] = neighborCount if (newGameGrid[x][y][2] == True): newGameGrid[x][y][3] = -1 #refresh active games activeGames = jsonIO.read("activeGames.json") #add new hame to active games newGame = { "type": "minesweeper", "time": datetime.now().isoformat("-"), "nextSpace": [-1, -1, "none", 0], "grid": newGameGrid, "gridSize": gridSize, "bombcount": bombcount, "comments": [row_id, col_id, act_id] } activeGames[message_id] = newGame jsonIO.rawWrite(activeGames, "activeGames.json") gameReacts = jsonIO.read("gameReacts.json") gameReacts[row_id] = message_id gameReacts[col_id] = message_id gameReacts[act_id] = message_id jsonIO.rawWrite(gameReacts, "gameReacts.json") decisionRow = [] decisionCol = [] for x in range(gridSize): decisionRow.append(baseRow[x]) decisionCol.append(baseCol[x]) gridMsg = str(gridToMsg(newGameGrid, gridSize, bombcount)) return [gridMsg, decisionRow, decisionCol, decisionAct]
def onReact(emoji_name, message_id): package = ["hmm"] activeGames = jsonIO.read("activeGames.json") gameReacts = jsonIO.read("gameReacts.json") game = activeGames[message_id] gridSize = game["gridSize"] bombcount = game["bombcount"] for e in emojicode: if (emoji_name == emojicode[e][0] or emoji_name == emojicode[e][3][0]): game["nextSpace"][emojicode[e][1]] = emojicode[e][2] #delete game if (emoji_name == emojicode["trash"][0]): for i in game["comments"]: gameReacts.pop(i, None) activeGames.pop(message_id, None) package = [ "delete", [ message_id, game["comments"][0], game["comments"][1], game["comments"][2] ] ] return package #check win condition if (checkWin(game, gridSize, bombcount)): #uncomment to show board on win #for y in range(gridSize): # for x in range(gridSize): # game["grid"][x][y][1]=True package = [ "react", gridToMsg(game["grid"], gridSize, bombcount), decisionWin, [game["comments"][0], game["comments"][1], game["comments"][2]] ] return package #action select elif (emoji_name == emojicode["click"][0]): game["nextSpace"][2] = "open" elif (emoji_name == emojicode["flag"][0]): game["nextSpace"][2] = "flag" #action confirmed elif (emoji_name == emojicode["check"][0] and game["nextSpace"][0] != -1 and game["nextSpace"][1] != -1 and game["nextSpace"][2] != "none"): if (game["nextSpace"][2] == "flag"): if (game["grid"][game["nextSpace"][0]][game["nextSpace"][1]][0] == True): game["grid"][game["nextSpace"][0]][game["nextSpace"] [1]][0] = False elif (game["grid"][game["nextSpace"][0]][game["nextSpace"][1]][1] == False): game["grid"][game["nextSpace"][0]][game["nextSpace"] [1]][0] = True package = ["edit", gridToMsg(game["grid"], gridSize, bombcount)] elif (game["nextSpace"][2] == "open"): if (game["grid"][game["nextSpace"][0]][game["nextSpace"][1]][0] == False and game["grid"][game["nextSpace"][0]][game["nextSpace"][1]][2] == True): #uncomment to show board on lose for y in range(gridSize): for x in range(gridSize): game["grid"][x][y][1] = True package = [ "react", gridToMsg(game["grid"], gridSize, bombcount), decisionLose, [ game["comments"][0], game["comments"][1], game["comments"][2] ] ] elif (game["grid"][game["nextSpace"][0]][game["nextSpace"][1]][0] == False): game["grid"][game["nextSpace"][0]][game["nextSpace"] [1]][1] = True gridOpen(game["grid"], game["nextSpace"][0], game["nextSpace"][1], gridSize) package = [ "edit", gridToMsg(game["grid"], gridSize, bombcount) ] else: package = [ "edit", gridToMsg(game["grid"], gridSize, bombcount) ] game["nextSpace"][0] = -1 game["nextSpace"][1] = -1 game["nextSpace"][2] = "none" elif (emoji_name == emojicode["check"][0]): package = ["edit", gridToMsg(game["grid"], gridSize, bombcount)] jsonIO.rawWrite(activeGames, "activeGames.json") jsonIO.rawWrite(gameReacts, "gameReacts.json") return package
"n": ["\U0001f1f3", 1, 13, [""]], "o": ["\U0001f1f4", 1, 14, [""]], "q": ["\U0001f1f6", 1, 16, [""]], "s": ["\U0001f1f8", 1, 18, [""]], "w": ["\U0001f1fc", 1, 22, [""]], "flag": ["\U0001f6a9", 3, 0, [""]], "click": ["\U00002196", 3, 0, [""]], "pop": ["\U0001f389", 3, 0, [""]], "trash": ["\U0001f5d1", 3, 0, [""]], "check": ["\U00002705", 3, 0, [""]], "turtle": ["\U0001F422", 3, 0, [""]], "pig": ["\U0001F437", 3, 0, [""]] } #load active games activeGames = jsonIO.read("activeGames.json") #game board min and max side length gridMin = 5 gridMax = 10 #emoji codes for game board bombEmoji = ["\U00002734\U0000FE0F", "\U0001F4A3", "\U0001F4A5"] numbersEmoji = [ "\U00002b1c", "\U00002b1b", emojicode["1"][0], emojicode["2"][0], emojicode["3"][0], emojicode["4"][0], emojicode["5"][0], emojicode["6"][0], emojicode["7"][0], emojicode["8"][0], emojicode["9"][0], emojicode["10"][0] ] lettersEmoji = [ ":octagonal_sign:", emojicode["a"][0], emojicode["b"][0], emojicode["c"][0], emojicode["d"][0], emojicode["e"][0], emojicode["f"][0],