private void aoe(Info info) { String msg = COLOR + Colors.BOLD; if (info.getMessage().length() > 4) { msg += info.getMessage().substring(5) + " "; } msg += "AOE in! Call out periodic status of how many hostiles are left."; info.sendMessage(msg); }
private void target(Info info) { if (raidTarget.containsKey(info.getChannel())) { info.sendMessage( COLOR + "The raid target is " + raidTarget.get(info.getChannel()) + " located at " + raidLocation.get(info.getChannel())); } else info.sendMessage("No target is set."); }
private void setTarget(Info info) { String factionInfo = info.getMessage().substring(11); String[] splitInfo = factionInfo.split("/"); if (splitInfo.length != 2) { info.sendMessage("usage for !setTarget is !setTarget <faction>/<location>"); } else { raidTarget.put(info.getChannel(), splitInfo[0]); raidLocation.put(info.getChannel(), splitInfo[1]); target(info); } }
private void go(Info info) { String msg = COLOR + Colors.BOLD + "MOVE OUT!"; if (raidTarget.get(info.getChannel()) != null) { msg += Colors.NORMAL + COLOR + " Target is " + raidTarget.get(info.getChannel()) + " " + raidLocation.get(info.getChannel()); } info.sendMessage(msg); }
private void setTick(Info info, String time) { int addon = 0; try { addon = Integer.parseInt(time); } catch (NumberFormatException e) { info.sendMessage( "Format exception. Command should be !setTick # where # is the number of minutes till the next tick."); } tickSetter = info.getSender(); tickTime = System.currentTimeMillis(); OFFSET = (Utils.getRealMinutes(info) + addon) % 15; info.sendMessage("Tick set to " + OFFSET + " minutes off."); }
public int fetchHeaders(final Info info, final Comment comment, final int[] serialno, Page page) { if (page == null) { page = new Page(); final int retValue = this.getNextPage(page, this.m_chunkSize); if (retValue == -128) { return -128; } if (retValue < 0) { return -130; } } if (serialno != null) { serialno[0] = page.serialno(); } this.m_oggStreamState.init(page.serialno()); info.init(); comment.init(); final Packet packet = new Packet(); int i = 0; while (i < 3) { this.m_oggStreamState.pagein(page); while (i < 3) { final int result = this.m_oggStreamState.packetout(packet); if (result == 0) { break; } if (result == -1) { info.clear(); this.m_oggStreamState.clear(); return -1; } if (info.synthesis_headerin(comment, packet) != 0) { info.clear(); this.m_oggStreamState.clear(); return -1; } ++i; } if (i < 3 && this.getNextPage(page, 1L) < 0) { info.clear(); this.m_oggStreamState.clear(); return -1; } } return 0; }
private void tick(Info info) { if (Utils.shouldDefer(info)) return; // else if (OFFSET == -1) { info.sendMessage( "Tick not sychronized yet. Wait for the next tick and execute /msg " + info.getBot().getName() + " !setTickor find out how long until the next tick and execute /msg " + info.getBot().getName() + " !setTick <mins>"); return; } int timeRemaining = 15 - ((15 + Utils.getRealMinutes(info) - OFFSET) % 15); long daysSinceSet = (System.currentTimeMillis() - tickTime) / (1000 * 60 * 60 * 24); info.sendMessage( timeRemaining + " minutes until the next tick (last set " + daysSinceSet + " days ago)"); }
/** Sets the time of the next scheduled raid */ private void setNextRaid(Info info) { String raidTime = info.getMessage().substring(13); raidTime = substituteTimeZone(raidTime); try { SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm z"); Date date = parser.parse(raidTime); TimeZone z = parser.getTimeZone(); GregorianCalendar cal = new GregorianCalendar(z); cal.setTime(date); raids.put(info.getChannel(), cal); saveRaids(); info.sendMessage("Raid time set."); } catch (ParseException e) { info.sendMessage( "Date format was bad. Date format is like \"2008-11-26 21:45 EST\". You entered " + raidTime); } }
private void tickAlarm(Info info) { if (OFFSET == -1) { info.sendMessage( "Tick not sychronized yet. Wait for the next tick and execute /msg " + info.getBot().getName() + " !setTick or find out how long until the next tick and execute /msg " + info.getBot().getName() + " !setTick <mins>"); return; } int timeRemaining = 15 - ((15 + Utils.getRealMinutes(info) - OFFSET) % 15); if (timeRemaining < 2) { info.sendMessage(Colors.BLUE + Colors.BOLD + "The tick is in " + timeRemaining + " minutes."); } else { PingTask ptask = new PingTask(info, "the tick is in one minute."); timer.schedule(ptask, (int) ((timeRemaining - 1) * 60 * 1000)); info.sendMessage("I'll alert you."); } }
private void nextRaid(Info info) { GregorianCalendar nextRaid = raids.get(info.getChannel()); GregorianCalendar now = Utils.getRealDate(info); int diffMins = (int) ((nextRaid.getTimeInMillis() - now.getTimeInMillis()) / 1000 / 60); if (nextRaid.compareTo(now) < 0) { info.sendMessage("There is no future raid set."); return; } String tz = info.getMessage().substring(9).trim(); tz = substituteTimeZone(tz); TimeZone timeZone; if (tz.length() == 0) timeZone = tZF("GMT"); else timeZone = tZF(tz); formatter.setTimeZone(timeZone); String ret = "The next raid is scheduled for " + formatter.format(nextRaid.getTime()); ret = ret + getTimeDifference(diffMins); info.sendMessage(ret); }
public boolean handleMessage(Info info) { String message = info.getMessage(); if (message.equalsIgnoreCase("!go")) { go(info); } else if (message.equalsIgnoreCase("!ward")) { ward(info); } else if (message.startsWith("!aoe")) { aoe(info); } else if (message.equalsIgnoreCase("!pile")) { pile(info); } else if (message.startsWith("!setPath")) { setPath(info); } else if (message.startsWith("!setTarget")) { setTarget(info); } else if (message.equalsIgnoreCase("!path")) { path(info); } else if (message.equalsIgnoreCase("!target")) { target(info); } else if (message.equalsIgnoreCase("!tanks")) { tanks(info); } else if (message.equalsIgnoreCase("!clearAll")) { clearStats(info); } else if (message.equalsIgnoreCase("!tick")) { tick(info); } else if (message.equalsIgnoreCase("!setTick")) { setTick(info); } else if (message.startsWith("!setTick ")) { String time = message.substring(9); setTick(info, time); } else if (message.equalsIgnoreCase("!whoSetTick")) { info.sendMessage("The tick was set by " + tickSetter + " at " + new Date(tickTime)); } else if (message.equalsIgnoreCase("!tickAlarm")) { tickAlarm(info); } else if (message.startsWith("!setnextraid ")) { setNextRaid(info); } else if (message.startsWith("!nextraid")) { nextRaid(info); } else return false; return true; }
@Override public void reset() { if (!this.m_isReset) { if (this.m_vorbisStream.isSeekable()) { this.rawSeek(this.m_dataOffsets[0]); } else { this.m_oggStreamState.clear(); this.m_block.clear(); this.m_dspState.clear(); if (this.m_info != null) { for (final Info info : this.m_info) { info.clear(); } } this.m_oggSyncState.clear(); try { if (this.m_vorbisStream != null) { this.m_vorbisStream.reset(); } } catch (Exception e) { JOrbisStream.m_logger.error((Object) "Exception", (Throwable) e); } this.m_links = 0; this.m_offset = 0L; this.m_offsets = null; this.m_dataOffsets = null; this.m_serialnos = null; this.m_pcmLengths = null; this.m_info = null; this.m_comments = null; this.m_pcmOffset = 0L; this.m_decodeReady = false; this.m_currentSerialno = 0; this.m_currentLink = 0; this.initialize(this.m_vorbisStream); } this.m_isReset = true; } }
@Override public List<File> generate() { Boolean generateApis = null; Boolean generateModels = null; Boolean generateSupportingFiles = null; Set<String> modelsToGenerate = null; Set<String> apisToGenerate = null; Set<String> supportingFilesToGenerate = null; // allows generating only models by specifying a CSV of models to generate, or empty for all if (System.getProperty("models") != null) { String modelNames = System.getProperty("models"); generateModels = true; if (!modelNames.isEmpty()) { modelsToGenerate = new HashSet<String>(Arrays.asList(modelNames.split(","))); } } if (System.getProperty("apis") != null) { String apiNames = System.getProperty("apis"); generateApis = true; if (!apiNames.isEmpty()) { apisToGenerate = new HashSet<String>(Arrays.asList(apiNames.split(","))); } } if (System.getProperty("supportingFiles") != null) { String supportingFiles = System.getProperty("supportingFiles"); generateSupportingFiles = true; if (!supportingFiles.isEmpty()) { supportingFilesToGenerate = new HashSet<String>(Arrays.asList(supportingFiles.split(","))); } } if (generateApis == null && generateModels == null && generateSupportingFiles == null) { // no specifics are set, generate everything generateApis = true; generateModels = true; generateSupportingFiles = true; } else { if (generateApis == null) { generateApis = false; } if (generateModels == null) { generateModels = false; } if (generateSupportingFiles == null) { generateSupportingFiles = false; } } if (swagger == null || config == null) { throw new RuntimeException("missing swagger input or config!"); } if (System.getProperty("debugSwagger") != null) { Json.prettyPrint(swagger); } List<File> files = new ArrayList<File>(); config.processOpts(); config.preprocessSwagger(swagger); config.additionalProperties().put("generatedDate", DateTime.now().toString()); config.additionalProperties().put("generatorClass", config.getClass().toString()); if (swagger.getInfo() != null) { Info info = swagger.getInfo(); if (info.getTitle() != null) { config.additionalProperties().put("appName", info.getTitle()); } if (info.getVersion() != null) { config.additionalProperties().put("appVersion", info.getVersion()); } if (info.getDescription() != null) { config .additionalProperties() .put("appDescription", config.escapeText(info.getDescription())); } if (info.getContact() != null) { Contact contact = info.getContact(); config.additionalProperties().put("infoUrl", contact.getUrl()); if (contact.getEmail() != null) { config.additionalProperties().put("infoEmail", contact.getEmail()); } } if (info.getLicense() != null) { License license = info.getLicense(); if (license.getName() != null) { config.additionalProperties().put("licenseInfo", license.getName()); } if (license.getUrl() != null) { config.additionalProperties().put("licenseUrl", license.getUrl()); } } if (info.getVersion() != null) { config.additionalProperties().put("version", info.getVersion()); } } StringBuilder hostBuilder = new StringBuilder(); String scheme; if (swagger.getSchemes() != null && swagger.getSchemes().size() > 0) { scheme = swagger.getSchemes().get(0).toValue(); } else { scheme = "https"; } hostBuilder.append(scheme); hostBuilder.append("://"); if (swagger.getHost() != null) { hostBuilder.append(swagger.getHost()); } else { hostBuilder.append("localhost"); } if (swagger.getBasePath() != null) { hostBuilder.append(swagger.getBasePath()); } String contextPath = swagger.getBasePath() == null ? "" : swagger.getBasePath(); String basePath = hostBuilder.toString(); String basePathWithoutHost = swagger.getBasePath(); // resolve inline models InlineModelResolver inlineModelResolver = new InlineModelResolver(); inlineModelResolver.flatten(swagger); List<Object> allOperations = new ArrayList<Object>(); List<Object> allModels = new ArrayList<Object>(); // models Map<String, Model> definitions = swagger.getDefinitions(); if (definitions != null) { List<String> sortedModelKeys = sortModelsByInheritance(definitions); if (generateModels) { if (modelsToGenerate != null && modelsToGenerate.size() > 0) { List<String> updatedKeys = new ArrayList<String>(); for (String m : sortedModelKeys) { if (modelsToGenerate.contains(m)) { updatedKeys.add(m); } } sortedModelKeys = updatedKeys; } for (String name : sortedModelKeys) { try { // don't generate models that have an import mapping if (config.importMapping().containsKey(name)) { continue; } Model model = definitions.get(name); Map<String, Model> modelMap = new HashMap<String, Model>(); modelMap.put(name, model); Map<String, Object> models = processModels(config, modelMap, definitions); models.putAll(config.additionalProperties()); allModels.add(((List<Object>) models.get("models")).get(0)); for (String templateName : config.modelTemplateFiles().keySet()) { String suffix = config.modelTemplateFiles().get(templateName); String filename = config.modelFileFolder() + File.separator + config.toModelFilename(name) + suffix; if (!config.shouldOverwrite(filename)) { continue; } String templateFile = getFullTemplateFile(config, templateName); String template = readTemplate(templateFile); Template tmpl = Mustache.compiler() .withLoader( new Mustache.TemplateLoader() { @Override public Reader getTemplate(String name) { return getTemplateReader( getFullTemplateFile(config, name + ".mustache")); } }) .defaultValue("") .compile(template); writeToFile(filename, tmpl.execute(models)); files.add(new File(filename)); } // to generate model test files for (String templateName : config.modelTestTemplateFiles().keySet()) { String suffix = config.modelTestTemplateFiles().get(templateName); String filename = config.modelTestFileFolder() + File.separator + config.toModelTestFilename(name) + suffix; if (!config.shouldOverwrite(filename)) { continue; } String templateFile = getFullTemplateFile(config, templateName); String template = readTemplate(templateFile); Template tmpl = Mustache.compiler() .withLoader( new Mustache.TemplateLoader() { @Override public Reader getTemplate(String name) { return getTemplateReader( getFullTemplateFile(config, name + ".mustache")); } }) .defaultValue("") .compile(template); writeToFile(filename, tmpl.execute(models)); files.add(new File(filename)); } } catch (Exception e) { throw new RuntimeException("Could not generate model '" + name + "'", e); } } } } if (System.getProperty("debugModels") != null) { LOGGER.info("############ Model info ############"); Json.prettyPrint(allModels); } // apis Map<String, List<CodegenOperation>> paths = processPaths(swagger.getPaths()); if (generateApis) { if (apisToGenerate != null && apisToGenerate.size() > 0) { Map<String, List<CodegenOperation>> updatedPaths = new TreeMap<String, List<CodegenOperation>>(); for (String m : paths.keySet()) { if (apisToGenerate.contains(m)) { updatedPaths.put(m, paths.get(m)); } } paths = updatedPaths; } for (String tag : paths.keySet()) { try { List<CodegenOperation> ops = paths.get(tag); Map<String, Object> operation = processOperations(config, tag, ops); operation.put("basePath", basePath); operation.put("basePathWithoutHost", basePathWithoutHost); operation.put("contextPath", contextPath); operation.put("baseName", tag); operation.put("modelPackage", config.modelPackage()); operation.putAll(config.additionalProperties()); operation.put("classname", config.toApiName(tag)); operation.put("classVarName", config.toApiVarName(tag)); operation.put("importPath", config.toApiImport(tag)); // Pass sortParamsByRequiredFlag through to the Mustache template... boolean sortParamsByRequiredFlag = true; if (this.config .additionalProperties() .containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) { sortParamsByRequiredFlag = Boolean.valueOf( (String) this.config .additionalProperties() .get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG) .toString()); } operation.put("sortParamsByRequiredFlag", sortParamsByRequiredFlag); processMimeTypes(swagger.getConsumes(), operation, "consumes"); processMimeTypes(swagger.getProduces(), operation, "produces"); allOperations.add(new HashMap<String, Object>(operation)); for (int i = 0; i < allOperations.size(); i++) { Map<String, Object> oo = (Map<String, Object>) allOperations.get(i); if (i < (allOperations.size() - 1)) { oo.put("hasMore", "true"); } } for (String templateName : config.apiTemplateFiles().keySet()) { String filename = config.apiFilename(templateName, tag); if (!config.shouldOverwrite(filename) && new File(filename).exists()) { continue; } String templateFile = getFullTemplateFile(config, templateName); String template = readTemplate(templateFile); Template tmpl = Mustache.compiler() .withLoader( new Mustache.TemplateLoader() { @Override public Reader getTemplate(String name) { return getTemplateReader( getFullTemplateFile(config, name + ".mustache")); } }) .defaultValue("") .compile(template); writeToFile(filename, tmpl.execute(operation)); files.add(new File(filename)); } // to generate api test files for (String templateName : config.apiTestTemplateFiles().keySet()) { String filename = config.apiTestFilename(templateName, tag); if (!config.shouldOverwrite(filename) && new File(filename).exists()) { continue; } String templateFile = getFullTemplateFile(config, templateName); String template = readTemplate(templateFile); Template tmpl = Mustache.compiler() .withLoader( new Mustache.TemplateLoader() { @Override public Reader getTemplate(String name) { return getTemplateReader( getFullTemplateFile(config, name + ".mustache")); } }) .defaultValue("") .compile(template); writeToFile(filename, tmpl.execute(operation)); files.add(new File(filename)); } } catch (Exception e) { throw new RuntimeException("Could not generate api file for '" + tag + "'", e); } } } if (System.getProperty("debugOperations") != null) { LOGGER.info("############ Operation info ############"); Json.prettyPrint(allOperations); } // supporting files Map<String, Object> bundle = new HashMap<String, Object>(); bundle.putAll(config.additionalProperties()); bundle.put("apiPackage", config.apiPackage()); Map<String, Object> apis = new HashMap<String, Object>(); apis.put("apis", allOperations); if (swagger.getHost() != null) { bundle.put("host", swagger.getHost()); } bundle.put("swagger", this.swagger); bundle.put("basePath", basePath); bundle.put("scheme", scheme); bundle.put("contextPath", contextPath); bundle.put("apiInfo", apis); bundle.put("models", allModels); bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar)); bundle.put("modelPackage", config.modelPackage()); List<CodegenSecurity> authMethods = config.fromSecurity(swagger.getSecurityDefinitions()); if (authMethods != null && !authMethods.isEmpty()) { bundle.put("authMethods", authMethods); bundle.put("hasAuthMethods", true); } if (swagger.getExternalDocs() != null) { bundle.put("externalDocs", swagger.getExternalDocs()); } for (int i = 0; i < allModels.size() - 1; i++) { HashMap<String, CodegenModel> cm = (HashMap<String, CodegenModel>) allModels.get(i); CodegenModel m = cm.get("model"); m.hasMoreModels = true; } config.postProcessSupportingFileData(bundle); if (System.getProperty("debugSupportingFiles") != null) { LOGGER.info("############ Supporting file info ############"); Json.prettyPrint(bundle); } if (generateSupportingFiles) { for (SupportingFile support : config.supportingFiles()) { try { String outputFolder = config.outputFolder(); if (isNotEmpty(support.folder)) { outputFolder += File.separator + support.folder; } File of = new File(outputFolder); if (!of.isDirectory()) { of.mkdirs(); } String outputFilename = outputFolder + File.separator + support.destinationFilename; if (!config.shouldOverwrite(outputFilename)) { continue; } String templateFile = getFullTemplateFile(config, support.templateFile); boolean shouldGenerate = true; if (supportingFilesToGenerate != null && supportingFilesToGenerate.size() > 0) { if (supportingFilesToGenerate.contains(support.destinationFilename)) { shouldGenerate = true; } else { shouldGenerate = false; } } if (shouldGenerate) { if (templateFile.endsWith("mustache")) { String template = readTemplate(templateFile); Template tmpl = Mustache.compiler() .withLoader( new Mustache.TemplateLoader() { @Override public Reader getTemplate(String name) { return getTemplateReader( getFullTemplateFile(config, name + ".mustache")); } }) .defaultValue("") .compile(template); writeToFile(outputFilename, tmpl.execute(bundle)); files.add(new File(outputFilename)); } else { InputStream in = null; try { in = new FileInputStream(templateFile); } catch (Exception e) { // continue } if (in == null) { in = this.getClass() .getClassLoader() .getResourceAsStream(getCPResourcePath(templateFile)); } File outputFile = new File(outputFilename); OutputStream out = new FileOutputStream(outputFile, false); if (in != null) { LOGGER.info("writing file " + outputFile); IOUtils.copy(in, out); } else { if (in == null) { LOGGER.error("can't open " + templateFile + " for input"); } } files.add(outputFile); } } } catch (Exception e) { throw new RuntimeException("Could not generate supporting file '" + support + "'", e); } } } config.processSwagger(swagger); return files; }
private void clearStats(Info info) { raidTarget.remove(info.getChannel()); raidLocation.remove(info.getChannel()); raidPath.remove(info.getChannel()); info.sendMessage("Raid status cleared."); }
private void ward(Info info) { String msg = COLOR + Colors.BOLD + "Start bashing. Call out when the ward is down."; info.sendMessage(msg); }
private void tanks(Info info) { String msg = COLOR + Colors.BOLD + "Tanks in! Call out when pets are cleared!"; info.sendMessage(msg); }
private void pile(Info info) { String msg = COLOR + Colors.BOLD + "Everyone in! Let's clear them out!"; info.sendMessage(msg); }
private void setPath(Info info) { String path = info.getMessage().substring(8); raidPath.put(info.getChannel(), path); info.sendMessage("The path to the target is set."); }
private void path(Info info) { if (raidPath.containsKey(info.getChannel())) { info.sendMessage(COLOR + raidPath.get(info.getChannel())); } else info.sendMessage("No path to the target is set."); }
private void setTick(Info info) { tickSetter = info.getSender(); tickTime = System.currentTimeMillis(); OFFSET = Utils.getRealMinutes(info) % 15; info.sendMessage("Tick set to " + OFFSET + " minutes off."); }