async def premiaza(ctx, quest_id: int, force= ''): s = session() # Get the author of the message and check if he is an admin in the database msgUser = User.getByDiscordID(s, ctx.author.id) if msgUser.is_admin == False: await ctx.send("Misto incercare bosule, dar nu esti tu bossul %s" %(ctx.author.name)) return # Is it forced reward? if force != '-f': force = False elif force == '-f': force = True # Reward all the mentioned users with the quest mentions = ctx.message.mentions for mention in mentions: user = User.getByDiscordID(s, mention.id) # Execute the give reward function and also check if it met all the conditions check = user.giveReward(s, quest_id, force) if check == False: await ctx.send("NU poti oferii premiul de la questul %s deoarece acesta nu este activ" % (quest_id)) return # Let users know that they were rewarded quest = Quest.getByID(s, quest_id) string = ('Pentru completarea cu succes a questului \'%s\' <@%s> a fost premiat cu:' % (quest.name, user.discord_id) +'\nxp: %s' % (quest.xp) +'\nsect coins: %s'% (quest.sect_coins) ) stringStartRanks = '' stringEndRanks = '' if quest.ranks.__len__() < 1: stringStartRanks = '\nrankul: ' else: stringStartRanks = '\nrankurile: ' for rank in quest.ranks: stringEndRanks = stringEndRanks + rank.name + ', ' string = string + stringStartRanks + stringEndRanks[:stringEndRanks.__len__() - 2] print(string) await ctx.send(string)
async def idee(ctx, text: str): s = session() user = User.getByDiscordID(s, ctx.author.id) ideea = Ideea(name = ctx.message.clean_content[6:], user = user) s.add(ideea) s.commit() print(text) await ctx.send("Ideea ta: \'%s\' \na fost inregistrata cu succes :D" % (ideea.name)) #TODO: hmmmmm, maybe change to admins owner = bot.get_user(256853098914381835) await owner.send(f"**{ctx.author.name}** a avut urmatoarea idee: \n*{ideea.name}*")
def updateUsers(): """ Update the discord server for new users, new nicknames, new names and new admins """ print("Checking Discord Users for updates") s = session() members = bot.get_all_members() for member in members: # Ignore bots if member.bot == True: continue user = User.getByDiscordID(s, member.id) #user = s.query(User).filter(User.discord_id == member.id).first() # If the user doesn't exist we add it to the database if user == None: print("Added discord user %s to the database" % (member.name)) user = User(discord_id = member.id, discord_name = member.name, discord_server_name = member.nick) s.add(user) s.commit() # Chekc if the user changed his name, update it if so if user.discord_name != member.name: print("Updated user's name %s to %s" %(user.discord_name, member.name)) user.discord_id = member.name s.commit() # Check if the nickname on the server changed, update it if so if user.discord_server_name != member.nick: print("Updated user's nick %s to %s" % (user.discord_server_name, member.nick)) user.discord_server_name = member.nick s.commit() # Check if the user has the admin role, update it if so count = 0 for role in member.roles: # TODO: GET THE ADMIN ROLE NAME FROM THE DATABASE INSTEAD, fro better scalability if role.name == 'QuesterADMIN' and user.is_admin == False: print("Updated user %s to admin role" %(user.discord_name)) user.is_admin = True s.commit() if role.name == 'QuesterADMIN' and user.is_admin == True: print(f'{user.discord_name} is already admin') count += 1 #if count == 0 and user.is_admin == True: #print('{user.discord_name} is not admin anymore'): # TODO: How to make this work with multiple servers ? s.close()
async def info(ctx): s = session() #await ctx.send('CURios mic ce esti, ia cu paine:') mentions = ctx.message.mentions for mention in mentions: user = User.getByDiscordID(s,mention.id) string = ('\nxp: %s' % (user.xp) + '\nsect coins: %s' % (user.sect_coins) ) stringRanks = '' stringStartRanks = '\nrankuri: ' for rank in user.ranks: stringRanks = stringRanks + rank.quest_rank.name + ', ' string = string + stringStartRanks + stringRanks[:stringRanks.__len__() - 2] await ctx.send(string)