Esempio n. 1
0
        protected override void AfterExecute(CommandInfo command)
        {
            ExecutionObject executionObj = Caching.ExecutionObjects[Context.Message.Id];

            //if (executionObj.Server != Server)
            Database.Execute(x =>
            {
                x.Store(Server);
                x.SaveChanges();
            });
            Caching.ExecutionObjects.Remove(Context.Message.Id);
        }
Esempio n. 2
0
        protected override void BeforeExecute(CommandInfo command)
        {
            ExecutionObject executionObj = Caching.ExecutionObjects[Context.Message.Id];

            Server     = executionObj?.Server;
            _oldServer = Server;
            if (Server == null || Context.Guild == null)
            {
                return;
            }
            Server.ServerId = Context.Guild.Id;
            Server.Name     = Context.Guild.Name;
        }
Esempio n. 3
0
        private async Task MessageReceived(SocketMessage msg)
        {
            try
            {
                if (msg.Author.IsBot || !(msg is SocketUserMessage message))
                {
                    return;
                }

                int argPos = 0;

                List <string> prefixes = new List <string>(_configuration.BotPrefixes);

                Server server = null;

                ExecutionObject executionObj;

                if (message.Channel is ITextChannel channel)
                {
                    IGuild guild = channel.Guild;
                    _database.Execute(x => { server = x.Load <Server>($"{guild.Id}") ?? new Server(); });

                    switch (server.BlockingType)
                    {
                    case BlockingType.Whitelist when !server.Whitelist.Contains(channel.Id):
                    case BlockingType.Blacklist when server.Blacklist.Contains(channel.Id):
                        return;

                    case BlockingType.None:
                        break;
                    }

                    prefixes.AddRange(server.Prefixes);

                    executionObj = new ExecutionObject {
                        Server = server
                    };
                }
                else
                {
                    executionObj = new ExecutionObject();
                }

                if (message.HasMentionPrefix(_client.CurrentUser, ref argPos) || prefixes.Any(x => message.HasStringPrefix(x, ref argPos, StringComparison.OrdinalIgnoreCase)))
                {
                    ShardedCommandContext context = new ShardedCommandContext(_client, message);
                    string parameters             = message.Content.Substring(argPos).TrimStart('\n', ' ');
                    _services.GetService <CachingService>().ExecutionObjects[message.Id] = executionObj;
                    IResult result = await _commands.ExecuteAsync(context, parameters, _services, MultiMatchHandling.Best);

                    Console.WriteLine($"User {message.Author.Username} in {context.Guild.Name}: {message.ToString()}");
                    if (!result.IsSuccess)
                    {
                        await HandleErrorAsync(result, context, parameters, server);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw new Exception(e.ToString());
            }
        }