Beispiel #1
0
 public GiphyModule(ChannelServices channelServices, GiphyApi api, ServerServices serverServices, Server server)
 {
     _channelServices = channelServices;
     _api             = api;
     _serverServices  = serverServices;
     _prefix          = _serverServices.GetGuildPrefix(server.Id).Result;
 }
Beispiel #2
0
        public async Task RollDice(int numberOfDice = 1)
        {
            if (numberOfDice > 10)
            {
                await ReplyAsync("You can not roll more than 10 dice at one time, " + Context.User.Mention);

                numberOfDice = 10;
            }
            else if (numberOfDice < 1)
            {
                await ReplyAsync("You need to roll at least 1 dice, " + Context.User.Mention);

                return;
            }

            EmbedBuilder eb = new EmbedBuilder()
                              .WithDescription(Context.User.Mention + " rolled " + numberOfDice + " 6-sided dice.");

            int totalOfRoll = 0;

            for (int i = 0; i < numberOfDice; i++)
            {
                var roll = _random.RandomNumber(1, 6);
                totalOfRoll += roll;

                eb.AddField("Dice " + (i + 1), roll.ToString(), true);
            }

            eb.AddField("Sum of roll", totalOfRoll);
            eb.WithFooter("Did you know? You can roll more dice by doing \"" +
                          _serverServices.GetGuildPrefix(Context.Guild.Id) + "rolldice [number of dice]\"!");

            await ReplyAsync("", false, eb.Build());
        }
Beispiel #3
0
        //private async Task OnJoinedGuild(SocketGuild arg)
        //{
        //    await arg.DefaultChannel.SendMessageAsync("Thank you for the invite !");
        //}

        //private async Task OnChannelCreated(SocketChannel arg)
        //{
        //    if ((arg as ITextChannel) == null) return;
        //    var channel = arg as ITextChannel;
        //    await channel.SendMessageAsync("Welcome to a new channel!");
        //}

        private async Task OnMessageReceived(SocketMessage arg)
        {
            if (!(arg is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }
            string[] filters = new string[] { "discord.gg", "mlk", "swear" };
            if (message.Content.Split(" ").Intersect(filters).Any())
            {
                await message.DeleteAsync();

                await message.Channel.SendMessageAsync($"{message.Author.Mention} you cannot write such stuff!");

                return;
            }
            if (message.Content.Contains("https://discord.gg/"))
            {
                if (!(message.Channel as SocketGuildUser).Guild.GetUser(message.Author.Id).GuildPermissions.Administrator)
                {
                    await message.DeleteAsync();

                    await message.Channel.SendMessageAsync($"{message.Author.Mention} you cannot send Discord invite links!");

                    return;
                }
            }
            if (message.Content == previousMessage)
            {
                await message.DeleteAsync();

                await message.Channel.SendMessageAsync($"{message.Author.Mention} please dont spam!");

                return;
            }
            previousMessage = message.Content;
            var argPos = 0;
            var prefix = await _serverServices.GetGuildPrefix((message.Channel as SocketGuildChannel).Guild.Id) ?? "!";

            if (!message.HasStringPrefix(prefix, ref argPos) && !message.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                return;
            }

            var context = new SocketCommandContext(_client, message);
            await _service.ExecuteAsync(context, argPos, _provider);
        }
        public async Task Prefix(string prefix = null)
        {
            if (prefix == null)
            {
                var guildPrefix = await _serverServices.GetGuildPrefix(Context.Guild.Id) ?? "!";
                await ReplyAsync($"The current prefix of this bot is `{guildPrefix}` .");

                return;
            }
            if (prefix.Length > 8)
            {
                await ReplyAsync("The lenght is out of bounds1");

                return;
            }
            await _serverServices.ModifyGuildPrefix(Context.Guild.Id, prefix);

            await ReplyAsync($"The prefix has been adjusted to `{prefix}` . ");

            await _serverServices.SendLogAsync(Context.Guild, "Prefix adjusted", $"{Context.User.Mention} modified the prefix to `{prefix}`");
        }