コード例 #1
0
        public async Task AddStream(CommandContext ctx, [Description("Specify the Twitch channel you want to add")] string channel,
                                    [Description("Mention the user to add")] string mention, [Description("Ping Here")] int ping)
        {
            var memberId = TwitchTasks.ParseMemberToId(mention);
            await ctx.Message.DeleteAsync();

            if (da.CanAddStream(channel, ctx.Guild.Id, ctx.Member.Id) > 0)
            {
                await ctx.RespondAsync("Failed To Add Stream, Member or Stream Already Added");

                return;
            }
            da.AddStream(channel, memberId, ctx.Guild.Id, ping);
            await ctx.RespondAsync($"{channel} has been added for <@!{memberId}>!");

            await TwitchTasks.LogAction($"<@!{ctx.Member.Id}> has enabled Stream Announcements for user <@!{memberId}> and channel https://twitch.tv/"
                                        + $"{channel}", ctx.Client);

            if (!TwitchOptions.AutoAssignRoles)
            {
                return;
            }
            try
            {
                var member = await ctx.Guild.GetMemberAsync(memberId);


                var streamerRole = GetRoleFromId(ctx.Guild.Id, "StreamerRole", ctx);

                await member.GrantRoleAsync(streamerRole);

                if (ping != 1)
                {
                    return;
                }

                var verifiedStreamerRole = GetRoleFromId(ctx.Guild.Id, "VerifiedRole", ctx);
                await member.GrantRoleAsync(verifiedStreamerRole);
            }
            catch (Exception e)
            {
                Ttv.Logger.LogError($"Error Assigning Roles {e.Message}");
            }
        }