Ejemplo n.º 1
0
 async def handle_language(self, message):
     if len(message.content)>3:
         lang = TextBlob(message.content)
         language = lang.detect_language()
         if language:
             if language not in read_file('data/languages.Json'):
                 write_file('data/languages.Json', 1, language)
             else:
                 x = read_file('data/languages.Json')
                 x[language]+=1
                 with open("data/languages.Json", 'w') as file_output_object:
                     json.dump(x, file_output_object, sort_keys=True, indent=4, separators=(',', ': '),
                               skipkeys=True)
Ejemplo n.º 2
0
    async def startprelim(self, ctx):
        if ctx.author.id in admin_list:
            channel = self.bot.get_channel(PRELIM_VOTING_CHANNEL)

            for i in read_file('data/suggestions.Json'):
                await self.post_suggestion(channel, i['suggestion'], i['jump_url'])
                time.sleep(.3)
Ejemplo n.º 3
0
 async def leaderboard(self, ctx, amount: int = 10):
     temp_dict = read_file('data/user_data.Json')
     points_dict = {}
     for i in temp_dict.keys():
         if "voice_points" in temp_dict[i]:
             points_dict[i] = temp_dict[i]["voice_points"] + temp_dict[i][
                 "text_points"]
     sorted_list = sorted(points_dict.items(), key=operator.itemgetter(1))
     sorted_list = list(reversed(sorted_list))
     del sorted_list[amount:]
     string = "```pl\n"
     x = 0
     for element in sorted_list:
         txt = element[0]
         usa = self.bot.get_user(int(txt))
         if usa is None:
             break
         val = element[1]
         val = f'{val:,}'.format(val=val)
         string = string + "{" + str(
             x + 1
         ) + "}     #" + usa.display_name + "\n        Points : [" + str(
             val) + "] " + "\n"
         x += 1
     string = string + '```'
     await ctx.send(string)
Ejemplo n.º 4
0
 def add_role_id_to_elections(self, role_id, user_id):
     self.election_contents = read_file("data/elections.Json")
     self.election_contents[str(user_id)].append({
         "nominee_role_id": role_id,
         "votes": []
     })
     self.write_to_file("data/elections.Json", self.election_contents)
Ejemplo n.º 5
0
 async def start_prelims(self):
     await self.voting_channel.set_permissions(self.ship_crew_role, read_messages=False)
     await self.prelim_voting_channel.purge(limit=300)
     await self.log_voting()
     await self.prelim_voting_channel.set_permissions(self.ship_crew_role, read_messages=True, send_messages=False)
     await self.prelim_voting_channel.set_permissions(self.sailor_role, read_messages=True, send_messages=False)
     for i in read_file('data/suggestions.Json'):
         await self.post_suggestion(self.prelim_voting_channel, i['suggestion'], i['jump_url'])
         time.sleep(.3)
     with open("data/suggestions.Json", "w") as f:
         f.write("[]")
Ejemplo n.º 6
0
 async def nominate(self, ctx, user: discord.Member, role: discord.Role):
     list_roles = [
         700732836772053013, 700732374471934053, 701964825227427941,
         700733089856356363, 724915974943408177
     ]
     channel = self.bot.get_channel(
         BALLOT_CHANNEL_ID)  # 703035799138074715,
     if role.id in list_roles:
         if not str(user.id) in read_file("data/elections.Json"):
             add_nominee(user.id, role.id)
         if self.role_id_not_in_elections(role.id, user.id):
             self.add_role_id_to_elections(role.id, user.id)
         if read_file("data/elections.Json")["message"] == False:
             message = await channel.send("_ _")
             self.election_contents["message"] = message.id
             self.write_to_file("data/elections.Json",
                                self.election_contents)
         message = await channel.fetch_message(
             int(read_file("data/elections.Json")["message"]))
         await update_nominations(ctx, message)
     else:
         await ctx.send("Role cannot be nominated")
Ejemplo n.º 7
0
 async def changelimit(self, ctx, limit: int):
     to_delete = read_file("data/to_delete.Json")
     if 0 > limit > 99:
         await ctx.send("Must provide a number between 0 and 99")
         return
     if ctx.channel.id in to_delete.values():
         vc_channel_id = list(to_delete.keys())[list(
             to_delete.values()).index(ctx.channel.id)]
         vc_channel = self.bot.get_channel(int(vc_channel_id))
         await vc_channel.edit(user_limit=limit)
         await ctx.send("Successfully changed limit")
     else:
         await ctx.send("Channel is not a private channel")
Ejemplo n.º 8
0
 async def start_prelims(self):
     await self.voting_channel.set_permissions(self.ship_crew_role,
                                               read_messages=False)
     await self.prelim_voting_channel.set_permissions(self.ship_crew_role,
                                                      read_messages=True,
                                                      send_messages=False)
     await self.prelim_voting_channel.set_permissions(self.sailor_role,
                                                      read_messages=True,
                                                      send_messages=False)
     for i in read_file('data/suggestions.Json'):
         await self.post_suggestion(self.prelim_voting_channel,
                                    i['suggestion'], i['jump_url'])
         time.sleep(.3)
Ejemplo n.º 9
0
 async def toplanguage(self, ctx, amount:int=10):
     x = read_file('data/languages.Json')
     temp = ""
     sorted_list = sorted(x.items(), key=operator.itemgetter(1))
     sorted_list = list(reversed(sorted_list))
     del sorted_list[amount:]
     for i in sorted_list:
         try:
             language = languages.get(alpha2=i[0])
             text = language.name
         except:
             text = i[0]
         temp+=text+": "+str(i[1]) + "\n"
     await ctx.send(temp)
Ejemplo n.º 10
0
 async def on_message(self, message):
     user_data_json = read_file("data/user_data.Json")
     if str(message.author.id) not in user_data_json:
         write_file('data/user_data.Json', {
             'voice_points': 0,
             'text_points': 1,
             'cooldown': time.time()
         }, str(message.author.id))
     else:
         user_data = user_data_json[str(message.author.id)]
         if time.time() - user_data['cooldown'] > 12:
             user_data['cooldown'] = time.time()
             user_data['text_points'] += 1
             write_file('data/user_data.Json', user_data,
                        str(message.author.id))
Ejemplo n.º 11
0
 async def viewwarns(self, ctx, *user: discord.User):
     if not user:
         user = ctx.author
     else:
         user = user[0]
     if user == ctx.author or ctx.author.id in config.moderators or ctx.author.id in config.admins:
         warns = read_file('data/warns.Json')
         warn_list = []
         for warn in warns:
             if warn["user_id"] == str(user.id):
                 warn_list.append(warn)
         embed=discord.Embed(title="Warnings", color=0x0d25cc)
         fields = 0
         for i in warn_list:
             embed.add_field(name="Warned at epoch " + str(i["epoch"]), value="Reason: " + str(i["reason"]))
             fields+=1
         if not fields > 0:
             await ctx.send("User was never warned ;) yayy!")
         else:
             await ctx.send(embed=embed)
Ejemplo n.º 12
0
 async def handle_tags(self, message):
     if str.lower(message.content) in read_file('data/tags.Json'):
         await message.channel.send(str(read_file('data/tags.Json')[str.lower(message.content)]))
Ejemplo n.º 13
0
 def role_id_not_in_elections(self, role_id, user_id):
     for nomination in read_file("data/elections.Json")[str(user_id)]:
         if role_id == nomination['nominee_role_id']:
             return False
     return True
Ejemplo n.º 14
0
 def __init__(self, bot):
     self.bot = bot
     self.election_contents = read_file("data/elections.Json")
Ejemplo n.º 15
0
 async def on_voice_state_update(self, member, before, after):
     channel = after.channel
     if channel is not None:
         if channel.id == 702169810028724297:  # 702169810028724297
             guild = member.guild
             category = self.bot.get_channel(
                 700665944279875654)  # 700665944279875654
             channel_number = random.randint(1111, 9999)
             while channel_number in self.list_numbers_banned:
                 channel_number = random.randint(1111, 9999)
             self.list_numbers_banned.append(channel_number)
             channel = await guild.create_voice_channel(
                 name="Private group {0}".format(channel_number),
                 user_limit=2,
                 category=category)  # create channel
             role = guild.get_role(700732374471934053)
             overwrite = {
                 guild.default_role:
                 discord.PermissionOverwrite(read_messages=False),
                 member:
                 discord.PermissionOverwrite(read_messages=True),
                 role:
                 discord.PermissionOverwrite(read_messages=True),
                 self.bot.user:
                 discord.PermissionOverwrite(manage_permissions=True,
                                             read_messages=True,
                                             manage_channels=True)
             }
             text_channel = await guild.create_text_channel(
                 name="private-group-{0}".format(channel_number),
                 category=category,
                 position=0,
                 overwrites=overwrite)
             message = "**__Welcome to your private chat room!__\n Only users who are in the designated voice channel can see this room! Please follow the rules as these rooms are moderated!\n\nYou can use the p!changelimit (p!cl) command to change the amount of members that can join your channel!\nHave fun!! ||{0} ping ;)||**".format(
                 member.mention)
             await text_channel.send(message)
             await member.move_to(channel)  # move member
             write_file(
                 self.to_delete, value=text_channel.id, key=str(
                     channel.id))  # adds channel id to the "to_delete" list
         to_delete_list = read_file(self.to_delete)
         if str(channel.id) in to_delete_list.keys():
             text_channel = self.bot.get_channel(to_delete_list[str(
                 channel.id)])
             await text_channel.set_permissions(member, read_messages=True)
     channel = before.channel
     if channel is not None:
         to_delete_list = read_file(self.to_delete)
         if len(channel.members) == 0 and str(
                 channel.id
         ) in to_delete_list.keys(
         ):  # checks if channel has no one and if it's in the "to_delete" list
             await channel.delete()
             text_channel = self.bot.get_channel(to_delete_list[str(
                 channel.id)])
             await text_channel.delete()
         elif str(channel.id) in to_delete_list.keys(
         ) and after.channel is not before.channel:
             text_channel = self.bot.get_channel(to_delete_list[str(
                 channel.id)])
             if not member.guild.get_role(
                     700732374471934053) in member.roles:
                 await text_channel.set_permissions(member,
                                                    read_messages=False)