async def check_watchlist(): print("Checking Watchlist...") global db_accounts global db_prices try: db_accounts = db.get('Accounts') except Exception as e: print("Failed to retrieve table 'Accounts' from db: " + str(e)) try: db_prices = db.get('Prices') except Exception as e: print("Failed to retrieve table 'Prices' from db: " + str(e)) for a in db_accounts.keys(): print("\tChecking Account " + str(a) + "'s Watchlist") try: watchlist = db_accounts[a]['watch'] for ticker in watchlist: price = db_prices[ticker] if watchlist[ticker] < 0.0: if price < (-1*watchlist[ticker]): msg = "<@" + str(a) + ">, your ticker " + ticker + " is now lower than watch value " + str(watchlist[ticker]) + "!" await send_alert(msg) return if price > watchlist[ticker]: msg = "<@" + str(a) + ">, your ticker " + ticker + " is now higher than watch value " + str(watchlist[ticker]) + '!' await send_alert(msg) return except KeyError as e: print("\tFailed to retrieve " + str(e) + " table from account " + str(a))
def add(self, data: dict): """ 数据添加 """ key = hash_code(data["url"]) last_data = db.get(key) db[key] = data return not bool(last_data)
async def on_message_delete(message): await bot.wait_until_ready() #práská, jaké zprávy maže jeden uživatel if (message.author.id == 704008259291447348): prijemce = bot.get_user(299914780712632332) await prijemce.send(message.author.name + ': ' + message.content) #ukládá do databáze smazané zprávy if (message.content != "smazat") and ( message.author != bot.user) and not (message.author.bot): print(message.content) if db.get(' deleted ') == None: db[' deleted '] = [] pole = db.get(' deleted ') pole.append([ message.guild.name, message.author.name, message.content, str(message.created_at) ]) db.set(' deleted ', pole)
def comments(): counts = db.get('emoji', {}) if flask.request.method == "POST" and 'emoji' in flask.request.form: emoji = flask.request.form['emoji'] if emoji in EMOJI: try: counts[emoji] += 1 except KeyError: counts[emoji] = 1 db['emoji'] = counts sorted_counts = sorted(counts.items(), key=lambda el: el[1], reverse=True) return flask.render_template('emoji.html', emoji=EMOJI, counts=sorted_counts)
def update_account_history_min(first, now): print("Updating Accounts...") global db_accounts try: db_accounts = db.get('Accounts') except Exception as e: print("Failed to retrieve table 'Accounts' from db: " + str(e)) for a in db_accounts.keys(): print('\tUpdating Account: ' + str(a)) day_of_week = datetime.datetime.today().weekday() my_val = get_total_value(db_accounts[a]) weekday_str = str(day_of_week) + '/' + str(now.hour) + '/' + str(now.minute) db_accounts[a]['history']['weekday'][weekday_str] = my_val if first: everyday_str = str(now.year) + '/' + str(now.month) + '/' + str(now.day) db_accounts[a]['history']['everyday'][everyday_str] = my_val read_accounts_to_db() print("\tFinished!")
def get_account_info(player): global accounts accounts = db.get('Accounts') try: target_account = accounts[str(player)] #if the player doesn't have an account in the database, create one for them except KeyError as e: print("Player ID " + str(e) + " not in DB, creating entry") my_json = { 'player_id': player, 'balance': 1000000, 'positions': {}, 'watch': {}, 'history': { 'weekday': {}, 'everyday': {} } } accounts[player] = my_json db['Accounts'] = accounts return my_json return target_account
async def update_prices(): print("Updating Prices...") global db_prices try: db_prices = db.get('Prices') except Exception as e: print("Failed to retrieve table 'Prices' from db: + " + str(e)) symbols = set() counter = 0 sleeper = 0 for a in db_prices: counter += 1 sleeper += 1 symbols.add(a) if counter == 199: try: bars = api.get_barset(symbols=symbols, timeframe='minute', limit=1) except Exception as e: print("API Failed: " + str(e)) for b in bars: if bars[b]: db_prices[b] = bars[b][0].c symbols = set() counter = 0 if sleeper % 1000 == 0: print("\tsleeping, sleeper = " + str(sleeper)) await asyncio.sleep(3) try: bars = api.get_barset(symbols=symbols, timeframe='minute', limit=1) except Exception as e: print("API Failed: " + str(e)) for b in bars: if bars[b]: db_prices[b] = bars[b][0].c read_prices_to_db() print("\tFinished!")
from random import randint, uniform from replit import db from flask import Flask, render_template, send_file, redirect from gevent.pywsgi import WSGIServer from json2html import json2html import numpy as np import requests app = Flask(__name__) vids = np.load('vids.npy').tolist() visits = db.get('visits', 0) @app.after_request def after_request(r): global visits visits += 1 db['visits'] = visits return r @app.route('/') def index(): return render_template('index/index.html', visits=visits)
async def on_message(message): if message.author == client.user: return said = message.content.lower() if 'hello!' in said and str(message.channel) != 'community-area': await message.channel.send('Have you kicked Nathan yet?') reason = await client.wait_for('message', check=lambda m: m.channel == message. channel and m.author == message.author) if 'no' in reason.content: await message.channel.send(':frowning:') elif 'ye' in reason.content: await message.channel.send('YAYY!!!') if 'bye!' in said and str(message.channel) != 'community-area': await message.channel.send('Kick Nathan!') if ('bored' in said and str(message.channel) != 'community-area') or 'bored!' in said: await message.channel.send('Why?') reason = await client.wait_for('message', check=lambda m: m.channel == message. channel and m.author == message.author) if 'tired' in reason.content: await message.channel.send(':sleeping:') else: await message.channel.send('Me too!') if 'im sad' in said: await message.channel.send('Why?') reason = await client.wait_for('message', check=lambda m: m.channel == message. channel and m.author == message.author) if 'idk' in reason.content: await message.channel.send(':frowning:\nHow can I help?') await client.wait_for('message', check=lambda m: m.channel == message.channel and m.author == message.author) await message.channel.send(f'sure!') else: await message.channel.send("It's alright! :slight_smile:") if '^-^' in said and str(message.channel) != 'community-area': await message.channel.send('^-^') if '!bleh' in said: with open('bleh.png', 'rb') as fp: await message.channel.send( file=discord.File(fp, 'new_filename.png')) if 'seeaaron' in said: await message.channel.send('Go Away!') if 'seedickson' in said: with open('dickson-pic.jpg', 'rb') as fp: await message.channel.send( file=discord.File(fp, 'new_filename.png')) if 'seemitchell' in said: with open('mitchell-pic.png', 'rb') as fp: await message.channel.send( file=discord.File(fp, 'new_filename.png')) if 'seaaaron' in said: await message.channel.send('Go Away!') if '!mochi' in said: with open('mochi.jpg', 'rb') as fp: await message.channel.send( file=discord.File(fp, 'new_filename.png')) if '!feedback' in said: await message.channel.send('Feedback noted!') if said == '!heads' or said == '!tails': randomGame = random.randint(1, 2) if randomGame == 1: randomGame = '!heads' else: randomGame = '!tails' if randomGame == said: await message.channel.send('You win!!!') else: await message.channel.send('You lost :frowning:') #id crisis if 'setname ' in said: identityList = open('identityList.txt', 'r') namesList = [] for line in identityList: namesList.append(line.split(',')[0]) identityList.close() # new identity idList = said.split(' ') print(f'MY ID IS <@{message.author.id}>') print(namesList) if f'<@{message.author.id}>' in namesList or f'<@!{message.author.id}>' in namesList: await message.channel.send('Go Away') else: await message.channel.send( f'<@{message.author.id}> {idList[1].title()}') identityList = open('identityList.txt', 'a') print( f'{message.author.mention},{idList[1].title()} {idList[2].title()}', file=identityList) identityList.close() # edit identity message identityList = open('identityList.txt', 'r') d = {} pinglist = [] content = '' print(f'identitylist is {identityList}') for line in identityList: line = line.rstrip().split(',') print(f'line is {line}') personName = line[1] if personName not in pinglist: pinglist.append(personName) else: personName = personName + '1' d[personName] = [line[0], personName] identityList.close() pinglist.sort() print(pinglist) channel = client.get_channel(757948169362473050) msg = await channel.fetch_message(759706606577123358) for person in pinglist: content += f'{d[person][0]} {person}\n' content = f'{len(pinglist)} people have solved the crisis\n{content}' await msg.edit(content=content) if 'setcode' in said: command, code, server = said.split(' ') amongwrite = open('amongcode.txt', 'w') print(f'{code},{server}', file=amongwrite) amongwrite.close() await message.channel.send('Saved!') if 'seecode' in said: em1 = discord.Embed(title="Among Us", colour=0xf2aaef) em1.set_footer( text= "This queue was autogenerated by Dhruv-Bot. Please donate bubble tea to support the creators." ) amongwrite = open('amongcode.txt', 'r') for line in amongwrite: code, server = line.rstrip().split(',') em1.add_field(name="Code", value=code.upper(), inline=True) em1.add_field(name="Server", value=server.title(), inline=True) await message.channel.send(embed=em1) amongwrite.close() if 'resettime' in said: amongfile = open('amongpeople.txt', 'r') personList = [] for line in amongfile: line = line.rstrip() if ':' not in line: personList.append(line) amongfile.close() amongfile = open('amongpeople.txt', 'w') for person in personList: print(person, file=amongfile) amongfile.close() await message.channel.send('Reset time!') elif 'settime' in said: timetoplay = said.split(' ')[1] amongfile = open('amongpeople.txt', 'a') print(timetoplay, file=amongfile) amongfile.close() await message.channel.send(f'Set time to {timetoplay}') if 'addppl' in said: personList = said.split(' ')[1::] amongfile = open('amongpeople.txt', 'a') for person in personList: print(person, file=amongfile) amongfile.close() await message.channel.send(f'Added {len(personList)} people!') if 'noping' in said: amongfile = open('amongpingpeople.txt', 'r') removeList = said.split(' ') personList = [] for line in amongfile: line = line.rstrip() if line != f"<@{message.author.id}>": personList.append(line) amongfile.close() amongfile = open('amongpingpeople.txt', 'w') for person in personList: print(person, file=amongfile) await message.channel.send('Oh...') if 'pingme' in said: amongfile = open('amongpingpeople.txt', 'a') print(f"<@{message.author.id}>", file=amongfile) amongfile.close() amongfile = open('amongpeople.txt', 'a') print(f"<@{message.author.id}>", file=amongfile) amongfile.close() await message.channel.send(f'Of course!') if 'pingall' in said: amongfile = open('amongpingpeople.txt', 'r') personList = [] for person in amongfile: personList.append(person.rstrip()) try: await message.channel.send('\n'.join(personList)) except: await message.channel.send('No one is on the list...') amongfile.close() if 'resetping' in said: amongfile = open('amongpingpeople.txt', 'w') amongfile.close() await message.channel.send('Reset!') if 'resetppl' in said: amongfile = open('amongpeople.txt', 'w') amongfile.close() amongfile = open('amongpingpeople.txt', 'w') amongfile.close() await message.channel.send('Reset!') if 'removeppl' in said: amongfile = open('amongpeople.txt', 'r') said = said.replace('!', '') removeList = said.split(' ') personList = [] for line in amongfile: line = line.rstrip() if line not in removeList: personList.append(line) amongfile.close() amongfile = open('amongpeople.txt', 'w') for person in personList: print(person, file=amongfile) await message.channel.send('Removed!') if 'showppl' in said: em1 = discord.Embed(title="Among Us", description="Player Queue", colour=0x00FFFF) amongfile = open('amongpeople.txt', 'r') amongList = [] timetoplay = '*no time set*' for line in amongfile: if ":" not in line: line = line.rstrip().title() amongList.append(line) else: timetoplay = line.rstrip() playerstring = '\n'.join(amongList) em1.add_field(name="Start Time", value=timetoplay, inline=True) em1.add_field(name="Player Count", value=len(amongList), inline=True) if len(playerstring) != 0: em1.add_field(name="Players", value=playerstring, inline=False) else: em1.add_field(name="Players", value="No one is playing", inline=False) em1.set_footer( text= "This queue was autogenerated by Dhruv-Bot. Please donate bubble tea to support the creators." ) msgcapture = await message.channel.send(embed=em1) await msgcapture.add_reaction('✅') await msgcapture.add_reaction('❌') amongfile = open('amongmsglog.txt', 'a') print(msgcapture.id, file=amongfile) amongfile.close() if str(message.channel) == 'among-us' and 'playing today' in said: em1 = discord.Embed(title="Among Us", description="Player Queue", colour=0x00FFFF) amongfile = open('amongpeople.txt', 'r') amongList = [] timetoplay = '*no time set*' for line in amongfile: if ":" not in line: line = line.rstrip().title() amongList.append(line) else: timetoplay = line.rstrip() playerstring = '\n'.join(amongList) em1.add_field(name="Start Time", value=timetoplay, inline=True) em1.add_field(name="Player Count", value=len(amongList), inline=True) if len(playerstring) != 0: em1.add_field(name="Players", value=playerstring, inline=False) else: em1.add_field(name="Players", value="No one is playing", inline=False) em1.set_footer( text= "This queue was autogenerated by Dhruv-Bot. Please donate bubble tea to support the creators." ) msgcapture = await message.channel.send(embed=em1) await msgcapture.add_reaction('✅') await msgcapture.add_reaction('❌') amongfile = open('amongmsglog.txt', 'a') print(msgcapture.id, file=amongfile) amongfile.close() if 'amongperson' in said: await message.channel.send( '⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣛⣛⣛⣻⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣟⣿⡿⠟⠛⠛⠛⠛⠻⠿⣿⣿⡿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣟⣾⡏⠀⠀⠀⠀⠀⢀⣀⣀⣀⣹⣿⣯⢿⣿⣿⣿\n⣿⣿⣿⣿⣿⣽⡿⠀⠀⠀⣴⣿⠿⠛⠛⠛⠛⠛⠻⠿⣮⡿⣿⣿\n⣿⡿⢟⣿⣿⣿⡇⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣽⣿\n⣿⣼⡟⠛⠉⣿⠀⠀⠀⠀⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣟⣿\n⣧⣿⠃⠀⢰⣿⠀⠀⠀⠀⠘⢿⣷⣤⣄⣀⣀⣤⣴⣶⣿⣟⣿⣿\n⡿⣿⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠉⠙⠛⠛⠋⠉⠉⠀⣿⣿⣿⣿\n⣻⣿⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⣿⣿\n⣿⣿⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⣿⣿\n⣿⣿⡀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⢿⣿⣿\n⣿⡽⣷⣦⣤⣿⡆⠀⠀⠀⠀⣠⣤⣤⣀⣀⣀⠀⠀⢸⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⣿⡏⡍⣿⡏⠀⠀⠀⣿⡏⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⣿⡇⣷⣿⣇⣀⣀⣀⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣝⢿⣶⣶⣶⣾⢟⣳⣿⣷⣽⣿⣿⣯⣯⣿⣿⣿⣿' ) if 'amongeject' in said: a, person = said.split(' ') person = person.title() await message.channel.send( f'. 。 • ゚ 。 .\n\n . . 。 。 . \n\n. 。 ඞ 。 . • •\n\n ゚ {person} was ejected . 。 .\n\n 1 Impostor remains 。\n\n ゚ . . , . .' ) if said[0] == '!' and '!among' in said: a, colour = said.split(' ') #colourList = ['black', 'red', 'blue', 'orange', 'cyan', 'pink', 'purple', 'brown', 'yellow', 'white', 'light-green', 'dark-green'] item = colourList[random.randint(0, len(colourList) - 1)] thing = str(message.author) if item == colour: if thing in db: db[thing] += 50 else: db[thing] = 50 await message.channel.send('You win +50') else: if thing in db: db[thing] -= 1 else: db[thing] = -1 await message.channel.send('You lose -1') await message.channel.send(f'You are now on {db[thing]} points!') elif said[0] == '!' and '!sus' in said: a, colour = said.split(' ') #colourList = ['black', 'red', 'blue', 'orange', 'cyan', 'pink', 'purple', 'brown', 'yellow', 'white', 'light-green', 'dark-green'] item = colourList[random.randint(0, len(colourList) - 1)] thing = str(message.author) if item == colour: db[thing] = int(db.get(thing, 0)) * 2 await message.channel.send('They were an impostor') else: db[thing] = int(float(int(db.get(thing, 0)) / 2)) await message.channel.send('There were a crewmate') await message.channel.send(f'You are now on {db[thing]} points!') elif said[0] == '!' and '!clear' in said: a, colour = said.split(' ') #colourList = ['black', 'red', 'blue', 'orange', 'cyan', 'pink', 'purple', 'brown', 'yellow', 'white', 'light-green', 'dark-green'] item = colourList[random.randint(0, len(colourList) - 1)] amongfile = open('among-game.txt', 'r') d = {} personList = set() for line in amongfile: thing, score = line.rstrip().split(',') d[thing] = score personList.add(thing) amongfile.close() amongfile = open('among-game.txt', 'w') thing = str(message.author) personList.add(thing) personList = list(personList) if item == colour: d[thing] = int(d.get(thing, 0)) * 2 await message.channel.send('They were impostor') else: d[thing] = int(float(int(d.get(thing, 0)) / 2)) await message.channel.send('They were a crewmate') for person in personList: print(f'{person},{d[person]}', file=amongfile) await message.channel.send(f'You are now on {d[thing]} points!') amongfile.close() if '!helpme' in said: await message.channel.send( f'The possible guesses are {", ".join(colourList)}.') if '!leaderboard' == said: personList = [] for person in db: personList.append(person) personList.sort(key=lambda x: int(db[x]), reverse=True) leader = '```css\n' for person in personList: leader += f'{person}: {db[person]}\n' leader += '```' await message.channel.send(leader) if 'reportrant' in said: em1 = discord.Embed(title="Anonymous Rant", description="autogenerated by Dhruv Bot") said = said[11::].title() em1.add_field(name='Rant', value=said) channel = client.get_channel(454530568059879424) await channel.send(embed=em1) if ' test1' in said: em1 = discord.Embed(title="Red", description="*this*\nnewline", colour=0x00FFFF) await message.channel.send(embed=em1) if "serverinfo" in said: server = message.guild embedded = discord.Embed(title=server.name, description='Server Info', color=0xEE8700) embedded.set_thumbnail(url=server.icon_url) roles = str(len(server.roles)) emojis = str(len(server.emojis)) channels = str(len(server.channels)) embedded.add_field( name="Created on:", value=server.created_at.strftime('%d %B %Y at %H:%M UTC+3'), inline=False) embedded.add_field(name="Server ID:", value=server.id, inline=False) embedded.add_field(name="Users on server:", value=server.member_count, inline=True) ##embedded.add_field(name="Default Channel:", value=server.default_channel, inline=True) embedded.add_field(name="Server Region:", value=server.region, inline=True) embedded.add_field(name="Verification Level:", value=server.verification_level, inline=True) embedded.add_field(name="Role Count:", value=roles, inline=True) embedded.add_field(name="Emoji Count:", value=emojis, inline=True) embedded.add_field(name="Channel Count:", value=channels, inline=True) await message.channel.send(embed=embedded)
from replit import db from datetime import datetime import json our_users = db.get("our_users") messages = db.get("messages") # print("users") # for user in our_users: # print(user) print("messages") for i in range(len(messages)): print(messages[i]) # to access the datetime docs: https://docs.python.org/3/library/datetime.html#datetime.datetime # stored = datetime.fromisoformat('2021-02-19 21:53:46.929000') # now = datetime.now() # if stored > now: # print(7) # else: # print(now)
def populate_db(): if not db.get("accounts"): db["accounts"] = []
app = Flask(__name__) CORS(app) @app.route('/') def app_index(): return render_template('index.html') @app.route('/<key>') def app_key(key): if (d := db.get(key)): d['views'] += 1 db[key] = d return redirect(db.get(key, {}).get('url', '/')) @app.route('/<key>.json') def app_key_data(key): return jsonify(db.get(key, {})) @app.route('/api/create', methods=['POST']) def api_create(): url = request.form['url'] chars = string.ascii_lowercase + string.ascii_uppercase + string.digits c = 4 key = ''.join([random.choice(chars) for i in range(c)]) while key in list(db.keys()): c += 1
def get_contact(name): number = db.get(name) return number
def app_key_data(key): return jsonify(db.get(key, {}))
def app_key(key): if (d := db.get(key)): d['views'] += 1 db[key] = d
import discord from dotenv import load_dotenv import alpaca_trade_api as alpaca from datetime import datetime #import time #import csv #import json import requests import matplotlib.pyplot as plt from replit import db #set up python env (used to access server environment variables) load_dotenv() #grab the accounts table accounts = db.get('Accounts') if accounts == None: print("Accounts table does not exist, creating...") accounts = {} db['Accounts'] = accounts #grab the prices table db_prices = db.get('Prices') if db_prices == None: print("Prices table does not exist, creating...") db_prices = {} db['Prices'] = db_prices #set up regex to recognize discord chat commands sell_order_regex = re.compile('^\!sell (.*) (.*)') buy_order_regex = re.compile('^\!buy (.*) (.*)')
file_name = 'TDTrackerMattZ.json' # Source url that we will be polling from url = 'https://mattz-cdn.geostyx.com/file/mattz-public/TDTrackerMattZ.json' s3 = boto3.resource('s3', endpoint_url='https://s3.us-west-002.backblazeb2.com') bucket = s3.Bucket('mattz-history') # DB keys so it's not hard coded strings everywhere class KEY: run_count = 'run_count' grab_file_hash = 'grab_file_hash' # init db stuff if it's not there if db.get(KEY.run_count) is None: db[KEY.run_count] = 0 if db.get(KEY.grab_file_hash) is None: db[KEY.grab_file_hash] = 'x' db[KEY.run_count] = db[KEY.run_count] + 1 print('Starting main loop ({0})'.format(db[KEY.run_count])) run_count = db[KEY.run_count] # MAIN LOOP TO UPDATE FILE while True: try: # Skip weekends dt = datetime.utcnow() isWeekend = (datetime.now(timezone('US/Eastern')).isoweekday() >= 6) if not isWeekend: # DOWNLOAD THE FILE
def get_prices(): global db_prices db_prices = db.get('Prices') return db_prices
async def on_message(message): if message.author == client.user: return said = message.content.lower() if 'hello!' in said and str(message.channel) != 'community-area': await message.channel.send('Have you kicked Nathan yet?') reason = await client.wait_for('message', check=lambda m: m.channel == message. channel and m.author == message.author) if 'no' in reason.content: await message.channel.send(':frowning:') elif 'ye' in reason.content: await message.channel.send('YAYY!!!') if 'bye!' in said and str(message.channel) != 'community-area': await message.channel.send('Kick Nathan!') if ('bored' in said and str(message.channel) != 'community-area') or 'bored!' in said: await message.channel.send('Why?') reason = await client.wait_for('message', check=lambda m: m.channel == message. channel and m.author == message.author) if 'tired' in reason.content: await message.channel.send(':sleeping:') else: await message.channel.send('Me too!') if 'im sad' in said: await message.channel.send('Why?') reason = await client.wait_for('message', check=lambda m: m.channel == message. channel and m.author == message.author) if 'idk' in reason.content: await message.channel.send(':frowning:\nHow can I help?') newreason = await client.wait_for( 'message', check=lambda m: m.channel == message.channel and m.author == message.author) await message.channel.send(f'sure! I will {newreason.content}') else: await message.channel.send("It's alright! :slight_smile:") if '^-^' in said and str(message.channel) != 'community-area': await message.channel.send('^-^') if '!bleh' in said: with open('bleh.png', 'rb') as fp: await message.channel.send( file=discord.File(fp, 'new_filename.png')) if '!mochi' in said: with open('mochi.jpg', 'rb') as fp: await message.channel.send( file=discord.File(fp, 'new_filename.png')) if 'randquote' == said: quoteFile = open('orwellquote.txt') counter = 0 d = {} for line in quoteFile: counter += 1 line = line.rstrip() d[counter] = line quotenum = random.randint(1, counter) await message.channel.send(d[quotenum]) if 'randorwell' in said: quoteFile = open('nef.txt') counter = 0 d = {} for line in quoteFile: counter += 1 line = line.rstrip() d[counter] = line quotenum = random.randint(1, counter) await message.channel.send(d[quotenum]) if '!feedback' in said: await message.channel.send('Feedback noted!') if said == '!heads' or said == '!tails': randomGame = random.randint(1, 2) if randomGame == 1: randomGame = '!heads' else: randomGame = '!tails' if randomGame == said: await message.channel.send('You win!!!') else: await message.channel.send('You lost :frowning:') #id crisis if 'setname ' in said: identityList = open('identityList.txt', 'r') namesList = [] for line in identityList: namesList.append(line.split(',')[0]) identityList.close() # new identity idList = said.split(' ') print(f'MY ID IS <@{message.author.id}>') print(namesList) if f'<@{message.author.id}>' in namesList or f'<@!{message.author.id}>' in namesList: await message.channel.send('Go Away') else: await message.channel.send( f'<@{message.author.id}> {idList[1].title()}') identityList = open('identityList.txt', 'a') print( f'{message.author.mention},{idList[1].title()} {idList[2].title()}', file=identityList) identityList.close() # edit identity message identityList = open('identityList.txt', 'r') d = {} pinglist = [] content = '' print(f'identitylist is {identityList}') for line in identityList: line = line.rstrip().split(',') print(f'line is {line}') personName = line[1] if personName not in pinglist: pinglist.append(personName) else: personName = personName + '1' d[personName] = [line[0], personName] identityList.close() pinglist.sort() print(pinglist) channel = client.get_channel(757948169362473050) msg = await channel.fetch_message(759706606577123358) for person in pinglist: content += f'{d[person][0]} {person}\n' content = f'{len(pinglist)} people have solved the crisis\n{content}' await msg.edit(content=content) if 'setcode' in said: command, code, server = said.split(' ') amongwrite = open('amongcode.txt', 'w') print(f'{code},{server}', file=amongwrite) amongwrite.close() await message.channel.send('Saved!') if 'seecode' in said: amongwrite = open('amongcode.txt', 'r') for line in amongwrite: code, server = line.rstrip().split(',') await message.channel.send(f'{server}\n{code.upper()}') amongwrite.close() if 'resettime' in said: amongfile = open('amongpeople.txt', 'r') personList = [] for line in amongfile: line = line.rstrip() if ':' not in line: personList.append(line) amongfile.close() amongfile = open('amongpeople.txt', 'w') for person in personList: print(person, file=amongfile) amongfile.close() await message.channel.send('Reset time!') elif 'settime' in said: timetoplay = said.split(' ')[1] amongfile = open('amongpeople.txt', 'a') print(timetoplay, file=amongfile) amongfile.close() await message.channel.send(f'Set time to {timetoplay}') if 'addppl' in said: personList = said.split(' ')[1::] amongfile = open('amongpeople.txt', 'a') for person in personList: print(person, file=amongfile) amongfile.close() await message.channel.send(f'Added {len(personList)} people!') if 'resetppl' in said: amongfile = open('amongpeople.txt', 'w') amongfile.close() await message.channel.send('Reset!') if 'removeppl' in said: amongfile = open('amongpeople.txt', 'r') removeList = said.split(' ') personList = [] for line in amongfile: line = line.rstrip() if line not in removeList: personList.append(line) amongfile.close() amongfile = open('amongpeople.txt', 'w') for person in personList: print(person, file=amongfile) await message.channel.send('Removed!') if 'showppl' in said: amongfile = open('amongpeople.txt', 'r') amongList = [] timetoplay = '*no time set*' for line in amongfile: if ":" not in line: line = line.rstrip().title() amongList.append(line) else: timetoplay = line.rstrip() await message.channel.send( f'There are {len(amongList)} people playing at {timetoplay}:') await message.channel.send('\n'.join(amongList)) if 'amongperson' in said: await message.channel.send( '⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣛⣛⣛⣻⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣟⣿⡿⠟⠛⠛⠛⠛⠻⠿⣿⣿⡿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣟⣾⡏⠀⠀⠀⠀⠀⢀⣀⣀⣀⣹⣿⣯⢿⣿⣿⣿\n⣿⣿⣿⣿⣿⣽⡿⠀⠀⠀⣴⣿⠿⠛⠛⠛⠛⠛⠻⠿⣮⡿⣿⣿\n⣿⡿⢟⣿⣿⣿⡇⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣽⣿\n⣿⣼⡟⠛⠉⣿⠀⠀⠀⠀⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣟⣿\n⣧⣿⠃⠀⢰⣿⠀⠀⠀⠀⠘⢿⣷⣤⣄⣀⣀⣤⣴⣶⣿⣟⣿⣿\n⡿⣿⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠉⠙⠛⠛⠋⠉⠉⠀⣿⣿⣿⣿\n⣻⣿⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⣿⣿\n⣿⣿⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⣿⣿\n⣿⣿⡀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⢿⣿⣿\n⣿⡽⣷⣦⣤⣿⡆⠀⠀⠀⠀⣠⣤⣤⣀⣀⣀⠀⠀⢸⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⣿⡏⡍⣿⡏⠀⠀⠀⣿⡏⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⣿⡇⣷⣿⣇⣀⣀⣀⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣝⢿⣶⣶⣶⣾⢟⣳⣿⣷⣽⣿⣿⣯⣯⣿⣿⣿⣿' ) if 'amongeject' in said: a, person = said.split(' ') person = person.title() await message.channel.send( f'. 。 • ゚ 。 .\n\n . . 。 。 . \n\n. 。 ඞ 。 . • •\n\n ゚ {person} was ejected . 。 .\n\n 1 Impostor remains 。\n\n ゚ . . , . .' ) if said[0] == '!' and '!among' in said: a, colour = said.split(' ') #colourList = ['black', 'red', 'blue', 'orange', 'cyan', 'pink', 'purple', 'brown', 'yellow', 'white', 'light-green', 'dark-green'] item = colourList[random.randint(0, len(colourList) - 1)] thing = str(message.author) if item == colour: if thing in db: db[thing] += 50 else: db[thing] = 50 await message.channel.send('You win +50') else: if thing in db: db[thing] -= 1 else: db[thing] = -1 await message.channel.send('You lose -1') await message.channel.send(f'You are now on {db[thing]} points!') elif said[0] == '!' and '!sus' in said: a, colour = said.split(' ') #colourList = ['black', 'red', 'blue', 'orange', 'cyan', 'pink', 'purple', 'brown', 'yellow', 'white', 'light-green', 'dark-green'] item = colourList[random.randint(0, len(colourList) - 1)] thing = str(message.author) if item == colour: db[thing] = int(db.get(thing, 0)) * 2 await message.channel.send('They were an impostor') else: db[thing] = int(float(int(db.get(thing, 0)) / 2)) await message.channel.send('There were a crewmate') await message.channel.send(f'You are now on {db[thing]} points!') elif said[0] == '!' and '!clear' in said: a, colour = said.split(' ') #colourList = ['black', 'red', 'blue', 'orange', 'cyan', 'pink', 'purple', 'brown', 'yellow', 'white', 'light-green', 'dark-green'] item = colourList[random.randint(0, len(colourList) - 1)] amongfile = open('among-game.txt', 'r') d = {} personList = set() for line in amongfile: thing, score = line.rstrip().split(',') d[thing] = score personList.add(thing) amongfile.close() amongfile = open('among-game.txt', 'w') thing = str(message.author) personList.add(thing) personList = list(personList) if item == colour: d[thing] = int(d.get(thing, 0)) * 2 await message.channel.send('They were impostor') else: d[thing] = int(float(int(d.get(thing, 0)) / 2)) await message.channel.send('They were a crewmate') for person in personList: print(f'{person},{d[person]}', file=amongfile) await message.channel.send(f'You are now on {d[thing]} points!') amongfile.close() if '!helpme' in said: await message.channel.send( f'The possible guesses are {", ".join(colourList)}.') if '!leaderboard' == said: personList = [] for person in db: personList.append(person) personList.sort(key=lambda x: int(db[x]), reverse=True) leader = '```css\n' for person in personList: leader += f'{person}: {db[person]}\n' leader += '```' await message.channel.send(leader)
def atrod_kont(vards): numurs = db.get(vards) return numurs