Пример #1
0
        private async void EventEnded(object sender, ElapsedEventArgs e)
        {
            EventInTimer tEvent = (EventInTimer)sender;

            tEvent.Elapsed -= EventEnded;
            tEvent.Stop();

            if (events.Count() > 0)
            {
                events.Remove(tEvent);
            }

            if (tEvent.dbEvent == null)
            {
                ShimakazeBot.Client.Logger.Log(LogLevel.Error,
                                               LogSources.TIMER_EVENT_EVENT, "Timer had no event attached");
                return;
            }

            var channel = await ShimakazeBot.Client.GetChannelAsync(tEvent.dbEvent.ChannelId);

            var eType = tEvent.dbEvent.Type;
            DiscordEmbedBuilder embedBuilder = new DiscordEmbedBuilder()
                                               .WithAuthor(ShimakazeBot.Client.CurrentUser.Username, null, ShimakazeBot.Client.CurrentUser.AvatarUrl)
                                               .WithColor(eType == EventType.REMINDER ? DiscordColor.Purple : DiscordColor.HotPink)
                                               .WithTimestamp(tEvent.dbEvent.EventTime)
                                               .WithTitle(eType == EventType.REMINDER ?
                                                          "Here's your reminder~~" : "Event Time! - イベント タイム!")
                                               .WithFooter($"Event #{tEvent.dbEvent.Id}")
                                               .WithDescription((string.IsNullOrWhiteSpace(tEvent.dbEvent.Message) ?
                                                                 "*No message.*" : tEvent.dbEvent.Message));

            if (eType == EventType.EVENT)
            {
                embedBuilder.AddField("Created by", $"<@{tEvent.dbEvent.UserId}>");
            }

            List <ulong> mentionUserIds = tEvent.dbEvent.MentionUserIdList.ToList();
            List <ulong> mentionRoleIds = tEvent.dbEvent.MentionRoleIdList.ToList();

            if (tEvent.dbEvent.Type == EventType.REMINDER)
            {
                mentionUserIds.Insert(0, tEvent.dbEvent.UserId);
            }
            string mentionString =
                (mentionUserIds.Count() > 0 ? $"<@{ string.Join("> <@", mentionUserIds)}> " : "") +
                (mentionRoleIds.Count() > 0 ? $" <@&{ string.Join("> <@&", mentionRoleIds)}> " : "");

            await CTX.SendSanitizedMessageAsync(channel, mentionString, false, embedBuilder);

            ShimakazeBot.DbCtx.TimedEvents.RemoveRange(
                ShimakazeBot.DbCtx.TimedEvents.Where(tE => tE.Id == tEvent.dbEvent.Id));
            await ShimakazeBot.DbCtx.SaveChangesAsync();
        }
Пример #2
0
        private async Task SkipSong(DiscordGuild guild, DiscordChannel channel,
                                    LavalinkGuildConnection lvc, bool fromVoteSkip = false)
        {
            string title = ShimakazeBot.playlists[guild].songRequests[0].track.Title;

            ShimakazeBot.playlists[guild].songRequests.RemoveAt(0);
            bool wasLooping = false;

            if (ShimakazeBot.playlists[guild].loopCount > 0)
            {
                wasLooping = true;
                ShimakazeBot.playlists[guild].loopCount = 0;
            }

            if (ShimakazeBot.playlists[guild].songRequests.Count > 0)
            {
                await lvc.PlayAsync(ShimakazeBot.playlists[guild].songRequests.First().track);

                await CTX.SendSanitizedMessageAsync(channel,
                                                    $"Skipped *{title}*{(wasLooping ? " and stopped loop" : "")}." +
                                                    (fromVoteSkip ?
                                                     $"\nSkip requested by **{ShimakazeBot.playlists[guild].voteSkip.requester.DisplayName}**" :
                                                     ""));
            }
            else
            {
                await lvc.StopAsync();

                await CTX.SendSanitizedMessageAsync(channel, $"Playlist ended with skip. (Skipped *{title}*" +
                                                    $"{(wasLooping ? " and stopped loop" : "")})" +
                                                    (fromVoteSkip ?
                                                     $"\nSkip requested by **{ShimakazeBot.playlists[guild].voteSkip.requester.DisplayName}**" :
                                                     ""));
            }

            ShimakazeBot.playlists[guild].voteSkip = null;
        }
Пример #3
0
        public async static void SendToDebugRoom(string text)
        {
            var channel = await Client.GetChannelAsync(Config.settings.debugRoom);

            await CTX.SendSanitizedMessageAsync(channel, text);
        }
Пример #4
0
        public async Task ShimaSay(CommandContext ctx, [RemainingText] string fullMessage)
        {
            if (fullMessage.Length == 0)
            {
                await CTX.RespondSanitizedAsync(ctx, "Please write the guild, channel and text");

                return;
            }
            string[] idArray      = fullMessage.Split(" ");
            int      channelIndex = fullMessage.IndexOf("#");

            DiscordGuild   guild   = null;
            DiscordChannel channel = null;


            // get guild
            ulong guildId = 0;

            if (!ulong.TryParse(idArray[0], out guildId))
            {
                if (channelIndex <= 0)
                {
                    await CTX.RespondSanitizedAsync(ctx,
                                                    "Please **ALSO** write the channel and text, or use IDs for both guild and channel.");

                    return;
                }

                string guildName = fullMessage.Substring(0, channelIndex - 1);
                if (guildName[guildName.Length - 1] == ' ') //fixes channel mentions
                {
                    guildName = guildName.Substring(0, guildName.Length - 1);
                }

                guild = ShimakazeBot.Client.Guilds.Values.ToList().FirstOrDefault(item => item.Name == guildName);
                if (guild == null)
                {
                    await CTX.RespondSanitizedAsync(ctx, $"Guild **{guildName}** not found!");

                    return;
                }
            }
            if (guild == null)
            {
                if (guildId == 0)
                {
                    await CTX.RespondSanitizedAsync(ctx, $"Guild ID **{guildId}** is not a valid ID!");

                    return;
                }
                else
                {
                    guild = ShimakazeBot.Client.Guilds.Values.ToList().FirstOrDefault(item => item.Id == guildId);
                    if (guild == null)
                    {
                        await CTX.RespondSanitizedAsync(ctx, $"Guild with ID **{guildId}** not found!");

                        return;
                    }
                }
            }

            // remove the guild
            if (channelIndex > 0)
            {
                idArray = fullMessage.Substring(channelIndex + 1).Split(" ");
            }
            else
            {
                idArray = idArray.Skip(1).ToArray();
            }

            // get channel
            ulong channelId = 0;

            if (channelIndex > 0 &&
                idArray[0] == $"{ctx.Message.MentionedChannels.ToList()[0].Id}>")
            {
                channelId = ctx.Message.MentionedChannels.ToList()[0].Id;
            }
            else if (!ulong.TryParse(idArray[0], out channelId) && channelIndex > 0)
            {
                channel = guild.Channels.Values.ToList().FirstOrDefault(item => item.Name == idArray[0]);
                if (channel == null)
                {
                    await CTX.RespondSanitizedAsync(ctx, $"Channel **{idArray[0]}** not found in **{guild.Name}**!");

                    return;
                }
            }
            if (channel == null)
            {
                if (channelId == 0)
                {
                    await CTX.RespondSanitizedAsync(ctx, $"Channel ID **{channelId}** is not a valid ID!");

                    return;
                }
                else
                {
                    channel = guild.Channels.Values.ToList().FirstOrDefault(item => item.Id == channelId);
                    if (channel == null)
                    {
                        await CTX.RespondSanitizedAsync(ctx,
                                                        $"Channel with ID **{channelId}** not found in **{guild.Name}**!");

                        return;
                    }
                }
            }

            // remove the channel
            idArray = idArray.Skip(1).ToArray();
            if (idArray.Length == 0)
            {
                await CTX.RespondSanitizedAsync(ctx, "Please **ALSO** write the text");

                return;
            }

            // get message
            string message = string.Join(" ", idArray);

            // send message
            await CTX.SendSanitizedMessageAsync(channel, message);

            await CTX.RespondSanitizedAsync(ctx, $"_{message}_ sent to **{channel.Name}** in **{guild.Name}**");
        }
Пример #5
0
 public static async Task <DiscordMessage> RespondSanitizedAsync(
     CommandContext ctx, string content = null, bool isTTS = false, DiscordEmbed embed = null,
     IEnumerable <IMention> mentions    = null)
 {
     return(await CTX.SendSanitizedMessageAsync(ctx.Channel, content, isTTS, embed, mentions));
 }