Exemple #1
0
        public override async Task <IResult> MessageReceived(TyniCommandContext context)
        {
            var message = context.Message;
            var channel = context.Channel;

            KeyValuePair <string, string> addition = ParseMsg(message);
            await message.DeleteAsync();

            var boardMsg = (await channel.GetMessagesAsync(1).FlattenAsync()).FirstOrDefault();

            Dictionary <string, string> board = StringToBoard(boardMsg.Content);

            if (board.ContainsKey(addition.Key))
            {
                board[addition.Key] = addition.Value;
            }
            else
            {
                board.Add(addition.Key, addition.Value);
            }

            await boardMsg.DeleteAsync();

            await channel.SendMessageAsync(BoardToString(board));

            return(ExecuteResult.FromSuccess());
        }
Exemple #2
0
        private async Task MessageReceived(SocketMessage msg)
        {
            // Take input and Validate
            var message = msg as SocketUserMessage;

            if (message == null)
            {
                return;                  // We only accept SocketUserMessages
            }
            if (message.Author.IsBot)
            {
                return;                       // We don't allow bots to talk to each other lest they take over the world!
            }
            var context = new TyniCommandContext(Client, Database, Settings, message);

            if (context == null || string.IsNullOrWhiteSpace(context.Message.Content))
            {
                return;                                                                        // Context must be valid and message must not be empty
            }
            // Do we have a custom channel listener?
            if (ChannelHandlers.ContainsKey(msg.Channel.Name))
            {
                await ChannelHandlers[msg.Channel.Name].MessageReceived(context);
            }
            // else Use the DefaultHandler
            else
            {
                await DefaultHandler.MessageReceived(context);
            }
        }
Exemple #3
0
        public async Task <IResult> TryParseCommand(TyniCommandContext context)
        {
            var message = context.Message;

            int cmdPos = 0;

            if (!(message.HasCharPrefix('!', ref cmdPos) || message.HasMentionPrefix(Client.CurrentUser, ref cmdPos)))
            {
                return(ExecuteResult.FromSuccess());
            }

            return(await Commands.ExecuteAsync(context, cmdPos, Services));
        }
Exemple #4
0
 public virtual async Task <IResult> MessageReceived(TyniCommandContext context)
 {
     return(await TryParseCommand(context));
 }