Example #1
0
    def shuffle_moves(self, n):
        """ Outputs a list of n random moves """

        shuffles = []
        for i in range(n):
            shuffles.append(self.rotation_types[sysrand().randrange(0,11)])
        return shuffles
Example #2
0
    def shuffle_moves(self, n):
        """ Outputs a list of n random moves """

        shuffles = []
        for i in range(n):
            shuffles.append(self.rotation_types[sysrand().randrange(0, 11)])
        return shuffles
Example #3
0
    async def log_cmd_error(self, ctx, error) -> str:
        cmd = ctx.command.qualified_name
        db = self.bot.db("logs")
        if not db.find("errors"):
            db.insert("errors", {})
        lower = string.ascii_lowercase
        digits = string.digits
        uuid = "".join(sysrand().choice(lower + digits) for _ in range(8))
        err = {
            uuid: {
                "cmd": cmd,
                "error": error,
                "author": str(ctx.author.id),
                "channel": str(ctx.channel.id),
                "guild": str(ctx.guild.id),
                "time": str(ctx.message.created_at),
            }
        }
        db.update("errors", err)
        cid = ctx.channel.id
        aid = ctx.author.id
        embed = discord.Embed()
        embed.title = f"Exception in command {cmd}"
        embed.description = f"```py\n{error}\n```"
        embed.timestamp = ctx.message.created_at
        embed.set_footer(text=f"Author: {aid} • Channel: {cid}")
        embed.set_author(name=f"Error ID: {uuid}")

        channel = await self.get_err_logs()
        try:
            await channel.send(embed=embed)
        except discord.errors.HTTPException:
            desc = embed.description
            first = desc[:2044] + "\n```"
            second = "```py\n" + desc[2044:]
            embed.description = first
            await channel.send(embed=embed)
            embed = discord.Embed(title="Exception continued",
                                  description=second)
            await channel.send(embed=embed)

        return uuid
Example #4
0
    async def log_error(self, error) -> str:
        db = self.bot.db("logs")
        if not db.find("errors"):
            db.insert("errors", {})
        lower = string.ascii_lowercase
        digits = string.digits
        uuid = "".join(sysrand().choice(lower + digits) for _ in range(8))
        err = {
            uuid: {
                "cmd": None,
                "error": error,
                "author": None,
                "channel": None,
                "guild": None,
                "time": None,
            }
        }
        db.update("errors", err)
        embed = discord.Embed()
        embed.title = "Non command exception occurred"
        embed.description = f"```py\n{error}\n```"
        embed.timestamp = dt.now()  # TODO: confirm that I can pass dt.now()
        embed.set_author(name=f"Error ID: {uuid}")

        channel = await self.get_err_logs()
        try:
            await channel.send(embed=embed)
        except discord.errors.HTTPException:
            desc = embed.description
            first = desc[:2044] + "\n```"
            second = "```py\n" + desc[2044:]
            embed.description = first
            await channel.send(embed=embed)
            embed = discord.Embed(title="Exception continued",
                                  description=second)
            await channel.send(embed=embed)

        return uuid
Example #5
0
#! /usr/bin/python

# Eric Gullufsen - Operating Systems I - Python Exploration (Program 5)
# August 4, 2015

import os
import string
from random import SystemRandom as sysrand

# Instantiate our random number generator object, which this implementation uses system 
# calls and is more secure (according to the pydocs) than the usual functions in the random module
generator = sysrand()

names = ["eric1.txt", "eric2.txt", "eric3.txt"]

# loop over the names array
for name in names:
	writey = ""
	# open a file for writing and reading, creating it if it doesn't yet exist
	with open(name, "w+") as filey:
		for x in range(10): # Ten random characters is what we need
			index = generator.randint(0,25) # get a pseudo-random index of the alphabet
			charizard = string.lowercase[index] # get character at that index
			writey += charizard 
		filey.write(writey)
		filey.seek(0) # jump back up to beginning of file before reading its contents into memory
		output = filey.read()
		print 'contents of {0} are: {1}\n'.format(name, output)
	
num_1 = generator.randint(1,42)
num_2 = generator.randint(1,42)