public async Task MessageReceivedAsync(SocketMessage rawMessage) { // Ignore system messages, or messages from other bots if (!(rawMessage is SocketUserMessage message)) { return; } if (message.Source != MessageSource.User) { return; } var context = new SocketCommandContext(_discord, message); //Save Game Importing if (message.Attachments.Count == 1) //The message contains an attachment. { if (IsEventActive()) { //An event is active. if (EventModule.IsParticipantRegistered(message.Author.Id)) { //Check to see if the user is registered. if (rawMessage.Attachments.FirstOrDefault <Attachment>().Filename.ToUpper().Contains("SA1")) { //The message contains a save file. Download and process it. string url = rawMessage.Attachments.FirstOrDefault <Attachment>().Url; string CacheDirectory = $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}Cache{Path.DirectorySeparatorChar}"; var Client = new WebClient(); Client.DownloadFile(new Uri(url), $"{CacheDirectory}{rawMessage.Author.Id}{rawMessage.Attachments.FirstOrDefault<Attachment>().Filename}"); Tools.BN6.SaveTool.ProcessSave($"{CacheDirectory}{rawMessage.Author.Id}{rawMessage.Attachments.FirstOrDefault<Attachment>().Filename}", rawMessage.Author.Id, EventModule.GetParticipant(rawMessage.Author).NetbattlerName); EventModule.MarkAsSubmitted(rawMessage.Author); await rawMessage.DeleteAsync(); await context.Channel.SendMessageAsync("Save file accepted."); } else if (rawMessage.Attachments.FirstOrDefault <Attachment>().Filename.ToUpper().Contains("SAV") || rawMessage.Attachments.FirstOrDefault <Attachment>().Filename.ToUpper().Contains(".SG")) { await rawMessage.DeleteAsync(); await context.Channel.SendMessageAsync("", false, EmbedTool.CommandError("I can only accept Save Files that are *.SA1 format. Please upload the correct save file.")); } } } } // This value holds the offset where the prefix ends var argPos = 0; if (!(message.HasMentionPrefix(_discord.CurrentUser, ref argPos) || message.HasStringPrefix("!", ref argPos))) { return; } var result = await _commands.ExecuteAsync(context, argPos, _services); if (result.IsSuccess == false) { //The command failed? } }
public void TestUseWithoutInit() { IEventModule anotherEventModule = new EventModule(); anotherEventModule.MainThreadId = Thread.CurrentThread.ManagedThreadId; Assert.Throws <InvalidOperationException>(() => anotherEventModule.SendEvent(null, new OneSimpleEventArgs())); Assert.Throws <InvalidOperationException>(() => anotherEventModule.ShutDown()); }
public void TestShutdownTwice() { IEventModule anotherEventModule = new EventModule(); anotherEventModule.MainThreadId = Thread.CurrentThread.ManagedThreadId; anotherEventModule.Init(); anotherEventModule.ShutDown(); Assert.Throws <InvalidOperationException>(() => anotherEventModule.ShutDown()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); NinjectModule eventModule = new EventModule(); NinjectModule userModule = new UserModule(); NinjectModule serviceModule = new ServiceModule("DefaultConnection"); var kernel = new StandardKernel(eventModule, userModule, serviceModule); DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); }
public void TestInitBeforeSettingMainThreadId() { IEventModule anotherEventModule = new EventModule(); Assert.Throws <InvalidOperationException>(() => anotherEventModule.Init()); }
public void CreateEvent() { eM = GameObject.Find("ChooseEventModule").GetComponent <EventModule>(); eM.CreateEvent(this.hostedEventName, eM.GetCalendarController().GetYear(), eM.GetCalendarController().GetMonth(), eM.GetCalendarController().GetWeekCounter().GetSelectedWeek()); eM.Disable(); }
public void CreateSchism(WS_Tile origin, EventModule module) { List <WS_Tile> closedTiles = new List <WS_Tile>(); List <WS_Tile> openTiles = new List <WS_Tile>(); float unrestPower = 500.0f; openTiles.Add(origin); while (openTiles.Count > 0) { WS_Tile currentTile = openTiles[0]; foreach (WS_Tile neighbor in currentTile.Neighbors()) { if (neighbor.population == 0.0f) { continue; } if (neighbor.government != origin.government || origin.government.capital == neighbor) { continue; } switch (module) { case EventModule.POPULATION: if (unrestPower > 100.0f && !openTiles.Contains(neighbor) && !closedTiles.Contains(neighbor)) { unrestPower -= (100.0f - currentTile.unrest); openTiles.Add(neighbor); } break; case EventModule.CULTURE: if (neighbor.culture == origin.culture && !openTiles.Contains(neighbor) && !closedTiles.Contains(neighbor)) { openTiles.Add(neighbor); } break; case EventModule.RELIGION: if (neighbor.religion == origin.religion && !openTiles.Contains(neighbor) && !closedTiles.Contains(neighbor)) { openTiles.Add(neighbor); } break; } } closedTiles.Add(currentTile); openTiles.RemoveAt(0); } if (closedTiles.Count > 4) { WS_Government newGov = new WS_Government(origin); newGov.rulingCulture = origin.culture; newGov.rulingReligion = origin.religion; newGov.preferredTech = (EventModule)Mathf.FloorToInt(Random.Range(0, (int)EventModule.MAX - 1)); foreach (WS_Tile tile in closedTiles) { tile.government = newGov; tile.unrest = tile.unrestCultural = tile.unrestReligious = 0.0f; } } }