t
This commit is contained in:
		
							parent
							
								
									8a3f399b1f
								
							
						
					
					
						commit
						97393e3ce2
					
				
					 4 changed files with 45 additions and 7 deletions
				
			
		
							
								
								
									
										18
									
								
								bot.js
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								bot.js
									
										
									
									
									
								
							|  | @ -12,13 +12,17 @@ const cfg = require('./config.json'); | ||||||
| const dir = dirname(import.meta.url); | const dir = dirname(import.meta.url); | ||||||
| 
 | 
 | ||||||
| const bot = new Eris(cfg.token); | const bot = new Eris(cfg.token); | ||||||
| const ctx = { | 
 | ||||||
|  | global.ctx = { | ||||||
| 	bot: bot, | 	bot: bot, | ||||||
| 	log_level: levels.DEBUG, | 	log_level: levels.DEBUG, | ||||||
|   whitelist: cfg.user_whitelist || [] | 	whitelist: cfg.user_whitelist || [], | ||||||
|  | 	set_ctx: (key, value) => { | ||||||
|  | 		global.ctx[key] = value; | ||||||
|  | 	}, | ||||||
| }; | }; | ||||||
| const log = new Logger(filename(import.meta.url), ctx.log_level); | const log = new Logger(filename(import.meta.url), global.ctx.log_level); | ||||||
| const parse = new CommandParser(ctx); | const parse = new CommandParser(global.ctx); | ||||||
| 
 | 
 | ||||||
| const checkGuild = (guild) => { | const checkGuild = (guild) => { | ||||||
| 	if (!cfg.whitelist.includes(guild.id)) { | 	if (!cfg.whitelist.includes(guild.id)) { | ||||||
|  | @ -34,7 +38,9 @@ bot.on('ready', () => { | ||||||
| 
 | 
 | ||||||
| bot.on('guildAvaliable', (guild) => checkGuild(guild)); | bot.on('guildAvaliable', (guild) => checkGuild(guild)); | ||||||
| 
 | 
 | ||||||
| bot.on('messageCreate', (msg) => parse.parseMsg(msg, ctx)); | bot.on('messageCreate', (msg) => parse.parseMsg(msg, global.ctx)); | ||||||
|  | 
 | ||||||
|  | bot.on('error', (err) => log.error(err.toString())); | ||||||
| 
 | 
 | ||||||
| bot.connect(); | bot.connect(); | ||||||
| 
 | 
 | ||||||
|  | @ -51,7 +57,7 @@ async function load_commands() { | ||||||
| 		} | 		} | ||||||
| 		if (obj.default != undefined) { | 		if (obj.default != undefined) { | ||||||
| 			if (obj.default.constructor.name == 'CommandInitializer') { | 			if (obj.default.constructor.name == 'CommandInitializer') { | ||||||
| 				obj.default.initialize(ctx); | 				obj.default.initialize(global.ctx); | ||||||
| 				let cmds = obj.default.getCommands(); | 				let cmds = obj.default.getCommands(); | ||||||
| 				if (parse.isCmd(cmds)) { | 				if (parse.isCmd(cmds)) { | ||||||
| 					parse.addCommand(cmds); | 					parse.addCommand(cmds); | ||||||
|  |  | ||||||
|  | @ -12,6 +12,10 @@ class LightsParser extends Command { | ||||||
| 	name = 'lights'; | 	name = 'lights'; | ||||||
| 	whitelist = true; | 	whitelist = true; | ||||||
| 	func(msg, args, ctx) { | 	func(msg, args, ctx) { | ||||||
|  | 		if (ctx.sleep) { | ||||||
|  | 			msg.channel.createMessage('i have sleep mode enabled. the lights are probably off.'); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
| 		if (!args.length) { | 		if (!args.length) { | ||||||
| 			msg.channel.createMessage('no args found.'); | 			msg.channel.createMessage('no args found.'); | ||||||
| 			return; | 			return; | ||||||
|  | @ -31,11 +35,23 @@ class LightsParser extends Command { | ||||||
| 				msg.channel.createMessage(`${response}`); | 				msg.channel.createMessage(`${response}`); | ||||||
| 			}, | 			}, | ||||||
| 			(error) => { | 			(error) => { | ||||||
| 				msg.channel.createMessage(`error.`); | 				msg.channel.createMessage(`error: ${error.message}`); | ||||||
| 			} | 			} | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| initializer.addCommand(new LightsParser()); | initializer.addCommand(new LightsParser()); | ||||||
| 
 | 
 | ||||||
|  | class Sleep extends Command { | ||||||
|  | 	name = 'sleep'; | ||||||
|  | 	whitelist = true; | ||||||
|  | 	func(msg, args, ctx) { | ||||||
|  | 		let sleep = ctx.sleep; | ||||||
|  | 		sleep = !sleep; | ||||||
|  | 		msg.channel.createMessage(`sleep mode is now ${sleep ? 'on' : 'off'}`); | ||||||
|  | 		ctx.set_ctx('sleep', sleep); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | initializer.addCommand(new Sleep()); | ||||||
|  | 
 | ||||||
| export default initializer; | export default initializer; | ||||||
|  |  | ||||||
|  | @ -16,6 +16,14 @@ const available_targets = { | ||||||
| 	g: new Target('g'), | 	g: new Target('g'), | ||||||
| 	b: new Target('b'), | 	b: new Target('b'), | ||||||
| 	stack: new Target('stack'), | 	stack: new Target('stack'), | ||||||
|  | 	stack2: new Target('stack2'), | ||||||
|  | 	stack3: new Target('stack3'), | ||||||
|  | 	stack4: new Target('stack4'), | ||||||
|  | 	stack5: new Target('stack5'), | ||||||
|  | 	stack6: new Target('stack6'), | ||||||
|  | 	stack6: new Target('stackr'), | ||||||
|  | 	stack6: new Target('stackg'), | ||||||
|  | 	stack6: new Target('stackb'), | ||||||
| 	tick: new Target('tick'), | 	tick: new Target('tick'), | ||||||
| 	index: new Target('index'), | 	index: new Target('index'), | ||||||
| }; | }; | ||||||
|  | @ -47,7 +55,11 @@ export const instructions = [ | ||||||
| 	{ n: 'MULTIPLY', a: true }, | 	{ n: 'MULTIPLY', a: true }, | ||||||
| 	{ n: 'DIVIDE', a: true }, | 	{ n: 'DIVIDE', a: true }, | ||||||
| 	{ n: 'MODULO', a: true }, | 	{ n: 'MODULO', a: true }, | ||||||
|  | 	{ n: 'FADE', a: true }, | ||||||
| 	{ n: 'RANDOM', a: false }, | 	{ n: 'RANDOM', a: false }, | ||||||
|  | 	{ n: 'JMP', a: false }, | ||||||
|  | 	{ n: 'JNZ', a: true }, | ||||||
|  | 	{ n: 'JEZ', a: true }, | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| export function initialize(ctx) { | export function initialize(ctx) { | ||||||
|  |  | ||||||
|  | @ -15,6 +15,10 @@ function padLeft(size = 4, str = '') { | ||||||
| export default function req(data, callback, errorCallback) { | export default function req(data, callback, errorCallback) { | ||||||
| 	let string_data = JSON.stringify(data); | 	let string_data = JSON.stringify(data); | ||||||
| 	let size = getBinarySize(string_data); | 	let size = getBinarySize(string_data); | ||||||
|  |   if (size > 9999) { | ||||||
|  |     errorCallback("too long"); | ||||||
|  |     return; | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
| 	let client = new net.Socket(); | 	let client = new net.Socket(); | ||||||
| 	client.connect(port, hostname, () => { | 	client.connect(port, hostname, () => { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue