class Redeem(): def __init__(self, bot: MilkBot): self.bot = bot self.keys = Config('redeem.json') @commands.command() @commands.guild_only() async def redeem(self, ctx: commands.Context): used_keys = { user: key for key, user in self.keys.all().items() if user } try: key = used_keys[ctx.author.id] except KeyError: try: key = next(k for k, u in self.keys.all().items() if not u) except StopIteration: await ctx.send( 'Error: Run out of keys to redeem. @Developer will need to generate more.' ) return await self.keys.put(key, ctx.author.id) await ctx.author.send(f"Your exclusive Lazarus Discord skin key: {key}" ) @commands.command() @commands.guild_only() @commands.has_permissions(manage_guild=True) async def addkeys(self, ctx: commands.Context, *keys: str): existing_keys = set(self.keys.all().keys()) keys = set(keys) new_keys = keys - existing_keys await self.keys.put_many(dict.fromkeys(new_keys)) await ctx.send(f"Added {len(new_keys)} keys") @commands.command() @commands.guild_only() @commands.has_permissions(manage_guild=True) async def redeemedkeys(self, ctx: commands.Context): redeemed_keys = {k: u for k, u in self.keys.all().items() if u} await ctx.send( f"Redeemed {len(redeemed_keys)} of {len(self.keys.all())} keys") @commands.command() @commands.guild_only() @commands.has_permissions(manage_guild=True) async def removekey(self, ctx: commands.Context, key): try: user_id = self.keys[key] if user_id and user_id != BLACKLIST: user = ctx.guild.get_member(user_id) user = user.mention if user else user_id await ctx.send(f"Key {key} owned by {user} blacklisted") else: raise KeyError() except KeyError: await ctx.send(f"Key {key} blacklisted") await self.keys.put(key, BLACKLIST) @commands.command() @commands.guild_only() @commands.has_permissions(manage_guild=True) async def lookupkey(self, ctx: commands.Context, key): try: user_id = self.keys[key] if user_id and user_id != BLACKLIST: user = ctx.guild.get_member(user_id) user = user.mention if user else user_id await ctx.send(f"Key {key} owned by {user}") elif user_id == BLACKLIST: await ctx.send(f"Key {key} blacklisted") else: await ctx.send(f"Key {key} unredeemed") except KeyError: await ctx.send(f"Key {key} not found")
log.logger_init("../log.conf") #解决stdout显示中文的问题 #python3.x代码 #sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') app = Flask(__name__, static_url_path='') from threading import Thread, current_thread logger.debug('子进程:%s,父进程:%s,线程:%r', os.getpid(), os.getppid(), current_thread()) config = Config('../config.json') try: confs = config.all() except Exception as e: logger.error("配置文件解析出错:%r", e) exit() model = Model("../model/") try: model.load_all(confs) except Exception as e: logger.error("加载Model出错:%r", e) exit() #注意!一定要放到加载了模型之后 graph = tf.get_default_graph() logger.debug("全局获得Graph:%r", graph)