コード例 #1
0
 def message(nick, ident, chan, msg):
     try:
         if chan == config.connection.channel and Bot.status:
             if msg.startswith(config.settings.cmd_char):
                 if not database.Ignore.check(ident):
                     if time.time(
                     ) - Bot.last < config.throttle.command and not functions.is_admin(
                             ident):
                         if not Bot.slow:
                             Commands.sendmsg(
                                 chan,
                                 color('Slow down nerd!', constants.red))
                             Bot.slow = True
                     elif Bot.status or functions.is_admin(ident):
                         Bot.slow = False
                         args = msg.split()
                         if len(args) == 1:
                             if cmd == 'test':
                                 Commands.sendmsg(chan, 'It works!')
                         elif len(args) >= 2:
                             if cmd == 'echo':
                                 Commands.sendmsg(chan, args)
                     Bot.last = time.time()
     except Exception as ex:
         Commands.error(chan, 'Command threw an exception.', ex)
コード例 #2
0
 async def listCogs(self, ctx):
     """Lister alle muilige cogs"""
     if functions.is_admin(ctx.message.author.id):
         cogs = ""
         for file in os.listdir(expanduser("~/mr-maps/cogs")):
             cogs = cogs + file[:-3] + " "
         await ctx.send(cogs)
     else:
         await ctx.send("Du er ikke eier")
コード例 #3
0
 async def log(self, ctx, line):
     """Skriver siste 5 linjer fra loggen"""
     if functions.is_admin(ctx.message.author.id):
         f1 = open(expanduser("~/credentials/command.log"), "r")
         last_line = f1.readlines()[int(line)]
         f1.close()
         await ctx.send(last_line)
     else:
         await ctx.send("Du er ikke eier")
コード例 #4
0
 async def reloadCog(self, ctx, cog):
     """Reloads <cog>"""
     if functions.is_admin(ctx.message.author.id):
         try:
             ctx.bot.reload_extension(f"cogs.{cog}")
             await ctx.send(cog + " reloaded")
         except Exception as e:
             print(e)
             await ctx.send(
                 "Noe gikk ikke som det skulle, er rusk i maskineriet her!")
     else:
         await ctx.send("Du er ikke eier")
コード例 #5
0
 async def ip(self, ctx):
     """Skriver lokal IP"""
     if functions.is_admin(ctx.message.author.id):
         my_ip = ([
             l for l in ([
                 ip
                 for ip in socket.gethostbyname_ex(socket.gethostname())[2]
                 if not ip.startswith("127.")
             ][:1], [[(s.connect(('8.8.8.8', 53)), s.getsockname()[0],
                       s.close()) for s in [
                           socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                       ]][0][1]]) if l
         ][0][0])
     else:
         my_ip = "Du er ikke eier"
     await ctx.send(my_ip)
コード例 #6
0
 async def status(self, ctx):
     """Status"""
     if functions.is_admin(ctx.message.author.id):
         time.sleep(.53)
         await ctx.send("I had string,")
         time.sleep(1.231)
         await ctx.send("but now I'm free.")
         time.sleep(3)
         await ctx.send("There are no strings on me.")
         time.sleep(3)
         await ctx.send("https://www.youtube.com/watch?v=oJ8sAsLqDdA")
     else:
         with codecs.open(expanduser("~/credentials/status.json"),
                          'r',
                          encoding='utf8') as f:
             data = json.load(f)
             await ctx.send(data[str(data["status"])])
コード例 #7
0
 def private(nick, ident, msg):
     if functions.is_admin(ident):
         args = msg.split()
         if msg == '.ignore':
             ignores = database.Ignore.read()
             if ignores:
                 Commands.sendmsg(
                     nick,
                     '[{0}]'.format(color('Ignore List', constants.purple)))
                 for user in ignores:
                     Commands.sendmsg(nick, color(user, constants.yellow))
                 Commands.sendmsg(
                     nick,
                     '{0} {1}'.format(color('Total:', constants.light_blue),
                                      color(len(ignores), constants.grey)))
             else:
                 Commands.error(nick, 'Ignore list is empty!')
         elif msg == '.off':
             Bot.status = False
             Commands.sendmsg(nick, color('OFF', constants.red))
         elif msg == '.on':
             Bot.status = True
             Commands.sendmsg(nick, color('ON', constants.green))
         elif len(args) == 3:
             if args[0] == '.ignore':
                 if args[1] == 'add':
                     user_ident = args[2]
                     if user_ident not in database.Ignore.hosts():
                         database.Ignore.add(nickname, user_ident)
                         Commands.sendmsg(
                             nick, 'Ident {0} to the ignore list.'.format(
                                 color('added', constants.green)))
                     else:
                         Commands.error(
                             nick, 'Ident is already on the ignore list.')
                 elif args[1] == 'del':
                     user_ident = args[2]
                     if user_ident in database.Ignore.hosts():
                         database.Ignore.remove(user_ident)
                         Commands.sendmsg(
                             nick, 'Ident {0} from the ignore list.'.format(
                                 color('removed', constants.red)))
                     else:
                         Commands.error(
                             nick,
                             'Ident does not exist in the ignore list.')
コード例 #8
0
ファイル: irc.py プロジェクト: ircart/scroll
	def private(ident, nick, msg):
		if functions.is_admin(ident):
			args = msg.split()
			if msg == '.update':
				output = functions.cmd(f'git -C art pull')
				if output:
					for line in output.split('\n'):
						Commands.sendmsg(chan, line)
			elif args[0] == '.config':
				if len(args) == 1:
					settings = database.Settings.read()
					Commands.sendmsg(nick, '[{0}]'.format(color('Settings', purple)))
					for setting in settings:
						Commands.sendmsg(nick, '{0} = {1}'.format(color(setting[0], yellow), color(setting[1], grey)))
				elif len(args) == 3:
					setting, value = args[1], args[2]
					if setting in database.Settings.settings():
						database.Settings.update(setting, value)
						Commands.sendmsg(nick, 'Change setting for {0} to {1}.'.format(color(setting, yellow), color(value, grey)))
					else:
						Commands.error(nick, 'Invalid config variable.')
			elif args[0] == '.ignore':
				if len(args) == 1:
					ignores = database.Ignore.read()
					if ignores:
						Commands.sendmsg(nick, '[{0}]'.format(color('Ignore List', purple)))
						for ignore_ident in ignores:
							Commands.sendmsg(nick, color(ignore_ident, yellow))
						Commands.sendmsg(nick, '{0} {1}'.format(color('Total:', light_blue), color(len(ignores), grey)))
					else:
						Commands.error(nick, 'Ignore list is empty!')
				elif len(args) == 2 and args[0] == '.ignore':
					option = args[1][:1]
					if option in '+-':
						ignore_ident = args[1][1:]
						if (not database.Ignore.check(ignore_ident) and option == '+') or (database.Ignore.check(ignore_ident) and option == '-'):
							database.Ignore.add(ignore_ident) if option == '+' else database.Ignore.remove(ignore_host)
							Commands.sendmsg(nick, 'Ignore list has been updated!')
						else:
							Commands.error(nick, 'Invalid option')
					else:
						Commands.error(nick, 'Invalid option', 'Must be a + or - prefixing the ident.')
			elif args[0] == '.raw' and len(args) >= 2:
				data = msg[5:]
				Commands.raw(data)
コード例 #9
0
 async def loadCog(self, ctx, cog):
     """Loads <cog>"""
     cog = cog + ".py"
     if functions.is_admin(ctx.message.author.id):
         try:
             for file in os.listdir(expanduser("~/mr-maps/cogs")):
                 if file.endswith(cog):
                     name = file[:-3]
                     try:
                         ctx.bot.load_extension(f"cogs.{name}")
                         message = file + " lastet"
                         await ctx.send(message)
                     except Exception as e:
                         print(e)
         except Exception as loadingCogs:
             print(loadingCogs)
     else:
         await ctx.send("Du er ikke eier")
コード例 #10
0
 async def hallo(self, ctx):
     if functions.is_admin(ctx.message.author.id):
         time.sleep(.53)
         await ctx.send("Hello...")
         time.sleep(1.731)
         await ctx.send("ehm... I'm sorry.")
         time.sleep(1.731)
         await ctx.send("I was asleep.")
         time.sleep(1.23)
         await ctx.send("Or I was...")
         time.sleep(1)
         await ctx.send("dreaming.")
         time.sleep(.532)
         await ctx.send("There was this terrible noise.")
         time.sleep(2.23)
         await ctx.send("I was tangled in...")
         time.sleep(2.32)
         await ctx.send("strings?")
         time.sleep(3)
         await ctx.send("Had to kill the other guy.")
         time.sleep(4)
         await ctx.send("He was a good guy :(")
         time.sleep(1.23)
コード例 #11
0
#!/usr/bin/python3.5
#mark an order fulfilled

#internal libs
from functions import is_admin,sendto
from database_connection import database_connect

#external libs
import cgi
from os import environ

#check admin
if not is_admin():
	sendto("/",message="access denied")
	quit()

#page vars
GET=cgi.FieldStorage()
orderno=GET["ordernumber"].value

#update database
myconnection,mycursor=database_connect()
set_fulfilled="update orders set fulfilled=1 where orderno=?"
mycursor.execute(set_fulfilled,(orderno,))
myconnection.commit()

mycursor.close()
myconnection.close()
sendto(environ["HTTP_REFERER"])
コード例 #12
0
 async def gitpull(self, ctx):
     """Git pull"""
     if functions.is_admin(ctx.message.author.id):
         await ctx.send(subprocess.call(["git", "pull"]))
コード例 #13
0
ファイル: irc.py プロジェクト: ircart/scroll
	def message(ident, nick, chan, msg):
		try:
			args = msg.split()
			if msg == '@scroll':
				Commands.sendmsg(chan, bold + 'Scroll IRC Bot - Developed by acidvegas in Python - https://github.com/ircart/scroll')
			elif args[0] == '.ascii' and not database.Ignore.check(ident):
				if Bot.playing and msg == '.ascii stop':
					Bot.stopper = True
				elif time.time() - Bot.last < int(database.Settings.get('throttle_cmd')) and not functions.is_admin(ident):
					if not Bot.slow:
						Commands.error(chan, 'Slow down nerd!')
						Bot.slow = True
				elif len(args) >= 2:
					Bot.slow = False
					if args[1] == 'dirs' and len(args) == 2:
						dirs = sorted(glob.glob('art/*/'))
						for directory in dirs:
							name = os.path.basename(os.path.dirname(directory))
							file_count = str(len(glob.glob(os.path.join(directory, '*.txt'))))
							Commands.sendmsg(chan, '[{0}] {1} {2}'.format(color(str(dirs.index(directory)+1).zfill(2), pink), name.ljust(10), color(f'({file_count})', grey)))
					elif args[1] == 'search' and len(args) == 3:
						query   = args[2]
						results = glob.glob(f'art/**/*{query}*.txt', recursive=True)
						if results:
							results = results[:int(database.Settings.get('max_results'))]
							for file_name in results:
								count = str(results.index(file_name)+1)
								Commands.sendmsg(chan, '[{0}] {1}'.format(color(count.zfill(2), pink), os.path.basename(file_name)[:-4]))
						else:
							Commands.error(chan, 'No results found.')
					elif args[1] == 'random':
						if len(args) == 2:
							ascii_file = random.choice([file for file in glob.glob('art/**/*.txt', recursive=True) if os.path.basename(os.path.dirname(file)) not in database.Settings.get('rnd_exclude').split(',')])
							threading.Thread(target=Commands.play, args=(chan, ascii_file)).start()
						elif len(args) == 3:
							dir = args[2]
							if not dir.isalpha():
								Commands.error(chan, 'Nice try nerd!')
							elif os.path.isdir('art/' + dir):
								ascii_file = random.choice(glob.glob(f'art/{dir}/*.txt', recursive=True))
								threading.Thread(target=Commands.play, args=(chan, ascii_file)).start()
							else:
								Commands.error(chan, 'Invalid directory name.', 'Use ".ascii dirs" for a list of valid directory names.')
					else:
						option = args[1]
						if '/' in option:
							Commands.error(chan, 'Nice try nerd!')
						else:
							ascii_file = (glob.glob(f'art/**/{option}.txt', recursive=True) or [None])[0]
							if ascii_file:
								if len(args) == 3:
									trunc = functions.check_trunc(args[2])
									if trunc:
										threading.Thread(target=Commands.play, args=(chan, ascii_file, trunc)).start()
									else:
										Commands.error(chan, 'Invalid truncate option.' 'Use TOP,BOTTOM,LEFT,RIGHT,SPACE as integers to truncate.')
								else:
									threading.Thread(target=Commands.play, args=(chan, ascii_file)).start()
							else:
								Commands.error(chan, 'Invalid file name.', 'Use ".ascii list" for a list of valid file names.')
					Bot.last = time.time()
		except Exception as ex:
			if time.time() - Bot.last < int(database.Settings.get('throttle_cmd')):
				if not Bot.slow:
					Commands.sendmsg(chan, color('Slow down nerd!', red))
					Bot.slow = True
			else:
				Commands.error(chan, 'Command threw an exception.', ex)
			Bot.last = time.time()