Skip to content

Commit

Permalink
nickprotect close #174
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Nov 16, 2017
1 parent a9da673 commit e006bc5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
50 changes: 41 additions & 9 deletions cogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,22 +1193,54 @@ async def options(self, ctx):
async def edit(self, ctx, name, *, value):
"""Edits an option"""
name = name.upper()
with open('data/options.json') as f:
options = json.load(f)
try:
options[name]
except KeyError:
return await ctx.send('Not a valid option. View all with `{p}options list`')
if name != 'NICKPROTECT':
with open('data/options.json') as f:
options = json.load(f)
try:
options[name]
except KeyError:
return await ctx.send('Not a valid option. View all with `{p}options list`')
else:
options[name] = value
if await ctx.updatedata('data/options.json', json.dumps(options, indent=4), f'Update option: {name}'):
await ctx.send('Option edited. Now wait for me to restart!')
else:
options[name] = value
if await ctx.updatedata('data/options.json', json.dumps(options, indent=4), f'Update option: {name}'):
await ctx.send('Option edited. Now wait for me to restart!')
await ctx.send('Use `{p}nickprotect` to modify nick protect options.', delete_after=2)

@options.command(name='list')
async def __list(self, ctx):
"""Lists all options"""
with open ('data/options.json') as f:
await ctx.send('```json\n' + json.dumps(json.load(f), indent=4) + '\n```')

@commands.group(invoke_without_command=True)
async def nickprotect(self, ctx):
'''Nick Protect Config'''
pass

@nickprotect.command()
async def append(self, ctx, serverid=None):
'''Adds a guild to nick protect'''
with open('data/options.json') as f:
options = json.load(f)
if serverid is None: serverid = ctx.guild.id
if serverid in options['NICKPROTECT']:
return await ctx.send('Server ID already in nickprotect.')
options['NICKPROTECT'].append(serverid)
if await ctx.updatedata('data/options.json', json.dumps(options, indent=4), f'Update option: {name}'):
await ctx.send('Server added. Now wait for me to restart!')

@nickprotect.command()
async def remove(self, ctx, serverid=None):
'''Removes a guild from nick protect'''
with open('data/options.json') as f:
options = json.load(f)
if serverid is None: serverid = ctx.guild.id
if serverid not in options['NICKPROTECT']:
return await ctx.send('Server ID not even in nickprotect.')
options['NICKPROTECT'].remove(serverid)
if await ctx.updatedata('data/options.json', json.dumps(options, indent=4), f'Update option: {name}'):
await ctx.send('Server removed. Now wait for me to restart!')

def setup(bot):
bot.add_cog(Utility(bot))
13 changes: 12 additions & 1 deletion selfbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

class Selfbot(commands.Bot):
'''
Custom Client for selfbot.py - Made by verix#7220
Custom Client for selfbot.py - Made by verix#7200
'''
_mentions_transforms = {
'@everyone': '@\u200beveryone',
Expand Down Expand Up @@ -180,6 +180,17 @@ async def on_message(self, message):
self.messages_sent += 1
self.last_message = time.time()
await self.process_commands(message)

async def on_member_update(self, before, after):
if before != self.user: return
if before.nick == after.nick: return
with open('data/options.json') as f:
options = json.load(f)
if before.guild.id in options['NICKPROTECT']:
try:
await after.edit(nick = None)
except:
pass

def get_server(self, id):
return discord.utils.get(self.guilds, id=id)
Expand Down

0 comments on commit e006bc5

Please sign in to comment.