Example #1
0
        private async Task MessageReceived(SocketMessage message)
        {
            try
            {
                new MessageReceivedHandler().HandleMessage(discordSocketClient, message, _logger, this);
            }
            catch (Exception ex)
            {
                //If a command fails its job. return a message to the user and log the error.
                Console.WriteLine(ex);
                await message.Channel.SendMessageAsync("", false,
                                                       EmbedBuilderExtension.NullEmbed("Error", ex.Message, null, null).Build());

                await _logger.Log(Logger.LogCode.error, ex.ToString());
            }
        }
Example #2
0
        public async Task MakeRequest(SocketMessage message)
        {
            //command: requestrole
            //command: requestverification
            //Request comes in with DiscordId + ScoresaberID

            ulong  DiscordId    = message.Author.Id;
            string ScoresaberId = message.Content.Substring(9);

            ScoresaberId = Regex.Replace(ScoresaberId, "[^0-9]", "");

            if (!ValidationExtension.IsDigitsOnly(ScoresaberId))
            {
                await message.Channel.SendMessageAsync("", false, EmbedBuilderExtension.NullEmbed("Wrong scoresaber ID", "Get you link from the url from your scoresaber page.", null, null).Build());

                return;
            }

            //GuildID AND ChannelID
            ulong guild_id         = 505485680344956928;
            ulong guild_channel_id = 549350982081970176;

            var guild   = _discordSocketClient.Guilds.FirstOrDefault(x => x.Id == guild_id);
            var channel = guild.Channels.First(x => x.Id == guild_channel_id) as IMessageChannel;

            var embedBuilder = new EmbedBuilder
            {
                Title        = message.Author.Username,
                ThumbnailUrl = message.Author.GetAvatarUrl(),
                Description  = "" +
                               "**Scoresaber ID:** " + ScoresaberId + "\n" +
                               "**Discord ID:** " + DiscordId + "\n" +
                               "**Scoresaber link:** https://scoresaber.com/u/" + ScoresaberId + " \n" +
                               "*Waiting for approval by a Staff*" + " \n\n" +
                               "***(Reminder) Type !bs link [Scoresaber ID]***",
                Color = Color.Orange
            };

            var sendMessage = await channel.SendMessageAsync("", false, embedBuilder.Build());

            await sendMessage.AddReactionAsync(new Emoji("✅"));

            await sendMessage.AddReactionAsync(new Emoji("⛔"));

            //await message.DeleteAsync();
        }
Example #3
0
        private async Task <string> GetData(string type, string endpoint)
        {
            string result = null;

            using (var Client = new HttpClient())
            {
                var url = new Uri(_baseUrl + _playerId + type + endpoint);
                var httpResponseMessage = await Client.GetAsync(url);

                if (httpResponseMessage.StatusCode != HttpStatusCode.OK && _message != null)
                {
                    await _message.Channel.SendMessageAsync("", false, EmbedBuilderExtension.NullEmbed("Scoresaber Error", $"Status code: {httpResponseMessage.StatusCode}").Build());

                    return(null);
                }

                httpResponseMessage.EnsureSuccessStatusCode();
                result = await httpResponseMessage.Content.ReadAsStringAsync();
            }
            return(result);
        }
Example #4
0
        public static bool HasCertainRoleInNBSG(this SocketMessage message, DiscordSocketClient discord, ulong RoleId)
        {
            var guildUser = new GuildService(discord, 505485680344956928).ConvertUserToGuildUser(message.Author);

            if (guildUser == null)
            {
                message.Channel.SendMessageAsync("", false, EmbedBuilderExtension.NullEmbed("Not in the NBSG Discord", $"You need to be in the Dutch Beat Saber Discord to use this command").Build());
                return(false);
            }

            foreach (var role in guildUser.Roles)
            {
                if (role.Id == RoleId)
                {
                    return(true);
                }
            }

            var roleName = discord.GetGuild(505485680344956928).GetRole(RoleId).Name;

            message.Channel.SendMessageAsync("", false, EmbedBuilderExtension.NullEmbed("Validation Error", $"You do not have the right to access this command. You would need to have the role: {roleName}").Build());

            return(false);
        }