Пример #1
0
 public async Task CancelGame()
 {
     try
     {
         //Logger.LogInternal($"Command 'CancelGame' executed by '{Context.Message.Author.Username}'");
         if (CheckAccess())
         {
             string returnMessage   = "No Game is currently running!";
             bool   hasCancelAccess = CheckCancelAccess();
             lock (SyncObj)
             {
                 RunningCommandInfo commandInfo = GetRunningCommandInfo(Context.Channel.Id);
                 if (commandInfo?.GameInstance != null)
                 {
                     if (Context.Message.Author.Id == commandInfo.UserId || hasCancelAccess)
                     {
                         RemoveChannelCommandInstance(Context.Channel.Id);
                         commandInfo.GameInstance.AbortGame();
                         returnMessage = "Cancelling current running game!";
                     }
                 }
             }
             await LogAndReplyAsync(returnMessage);
         }
     }
     catch (Exception ex)
     {
         await Logger.Log(new LogMessage(LogSeverity.Error, "CancelGame", "Unexpected Exception", ex));
     }
 }
Пример #2
0
 public static bool CreateChannelCommandInstance(string commandName, ulong userId, ulong channelId, ulong guildId, BotGameInstance gameInstance, out RunningCommandInfo instance)
 {
     lock (SyncObj)
     {
         ChannelCommandInstances.TryGetValue(channelId, out instance);
         if (instance == null)
         {
             instance = new RunningCommandInfo(commandName, userId, channelId, guildId, gameInstance);
             ChannelCommandInstances[channelId] = instance;
             return(true);
         }
     }
     return(false);
 }