Exemplo n.º 1
0
 private void OneSecondTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (_Finish > 0)   //A little delay for the plot not to miss the last setpoint
     {
         if (_Finish++ > 3)
         {
             Stop();
         }
         return;
     }
     if (DelaySegmentStart && !_Reached && (TemperatureValidationCallback != null))
     {
         var t = TemperatureValidationCallback.Invoke();
         _Reached = (Math.Abs(t.Item1 - t.Item2) < DelayTolerance);
         if (!_Reached)
         {
             return;
         }
     }
     if (CustomCommands.ContainsKey(ElapsedTime))
     {
         TimeToIssueCustomCommand?.Invoke(this, new CustomCommandEventArgs(CustomCommands[ElapsedTime]));
     }
     if (++ElapsedTime >= _Enumerator.Current.Key)
     {
         _Reached = false;
         TimeToChangeSetpoint?.Invoke(this, new TemperatureEventArgs(this[_Enumerator.Current.Key]));
         if (!_Enumerator.MoveNext())
         {
             _Finish++;
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if message is a command, and executes it
        /// </summary>
        /// <param name="parameterMessage">The message to check</param>
        public async Task HandleCommand(SocketMessage parameterMessage)
        {
            Task.Run(async() =>
            {
                var message = parameterMessage as SocketUserMessage;
                if (!(message.Channel is IDMChannel))
                {
                    var guildId = ((SocketGuildChannel)message.Channel).Guild.Id;
                    MessagesPerGuild[guildId] = MessagesPerGuild.ContainsKey(guildId) ? MessagesPerGuild[guildId] + 1 : 1;
                }

                //Add experience the size of the message length

                /*if(message.Channel is SocketGuildChannel channel && (!message.Author.IsBot || message.Author.Id == Program.Client.CurrentUser.Id)){
                 *  if((DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).Minutes >= 2 && channel.Guild.MemberCount <= 10000){
                 *      await MopsBot.Data.Entities.User.ModifyUserAsync(message.Author.Id, x => {
                 *          x.CharactersSent += message.Content.Length;
                 *          x.AddGraphValue(message.Content.Length);
                 *      });
                 *  }
                 * }*/

                if (message == null || (message.Author.IsBot && !message.Content.StartsWith("[ProcessBotMessage]")))
                {
                    return;
                }

                // Mark where the prefix ends and the command begins
                int argPos = 0;

                //Determines if the Guild has set a special prefix, if not, ! is used
                ulong id = 0;
                if (message.Channel is Discord.IDMChannel)
                {
                    id = message.Channel.Id;
                }
                else
                {
                    id = ((SocketGuildChannel)message.Channel).Guild.Id;
                }
                var prefix = await GetGuildPrefixAsync(id);

                // Determine if the message has a valid prefix, adjust argPos
                if (!message.Content.StartsWith("[ProcessBotMessage]") && !(message.HasMentionPrefix(client.CurrentUser, ref argPos) || message.HasStringPrefix(prefix, ref argPos) || message.HasCharPrefix('?', ref argPos)))
                {
                    return;
                }

                if (char.IsWhiteSpace(message.Content[argPos]))
                {
                    argPos += 1;
                }

                var context = new ShardedCommandContext(client, message);

                if (message.HasCharPrefix('?', ref argPos))
                {
                    await commands.Commands.First(x => x.Name.Equals("help")).ExecuteAsync(context, new List <object> {
                        $"{context.Message.Content.Substring(argPos)}"
                    }, new List <object> {
                    }, _provider);
                    return;
                }

                if (message.Content.StartsWith("[ProcessBotMessage]"))
                {
                    argPos = "[ProcessBotMessage]".Length;
                }

                //Execute if command exists
                if (commands.Search(context, argPos).IsSuccess)
                {
                    /*if((await MopsBot.Data.Entities.User.GetUserAsync(message.Author.Id)).IsBanned){
                     *  await context.Channel.SendMessageAsync("You are banned from using Mops.");
                     *  return;
                     * }*/

                    await Program.MopsLog(new LogMessage(LogSeverity.Info, "", $"{parameterMessage.Author} ({parameterMessage.Author.Id}) executed command: {parameterMessage.Content.Substring(argPos)}"));
                    var result = await commands.ExecuteAsync(context, argPos, _provider);
                }

                //Else execute custom commands
                else if (!message.Author.IsBot && CustomCommands.ContainsKey(context.Guild.Id) && CustomCommands[context.Guild.Id].Commands.ContainsKey(context.Message.Content.Substring(argPos).Split(" ").First()))
                {
                    if (CustomCommands[context.Guild.Id].CheckPermission(context.Message.Content.Substring(argPos).Split(" ").First(), (SocketGuildUser)context.User))
                    {
                        /*if((await MopsBot.Data.Entities.User.GetUserAsync(message.Author.Id)).IsBanned){
                         *  await context.Channel.SendMessageAsync("You are banned from using Mops.");
                         *  return;
                         * }*/

                        await Program.MopsLog(new LogMessage(LogSeverity.Info, "", $"executed command: {parameterMessage.Content.Substring(argPos)}"));
                        await commands.Commands.First(x => x.Name.Equals("UseCustomCommand")).ExecuteAsync(context, new List <object> {
                            $"{context.Message.Content.Substring(argPos)}"
                        }, new List <object> {
                        }, _provider);
                    }
                }
            });
        }