Пример #1
0
        private async Task UpdateActivityAsync()
        {
            StreamingGame game = Config.Instance.Maintenance
                ? new StreamingGame("maintenance", Config.Instance.URIs.TwitchURL)
                : new StreamingGame($"{this.Prefix}help | {this.Prefix}info | {this.Prefix}docs",
                                    Config.Instance.URIs.TwitchURL);

            await this.DiscordClient.SetActivityAsync(game);
        }
Пример #2
0
            public async Task SetActivityStream(string streamUrl = null, [Remainder] string activityMessage = null)
            {
                if (streamUrl == null || activityMessage == null)
                {
                    await ReplyAsync("**Syntax:** " + Guild.Load(Context.Guild.Id).Prefix + "editconfig setstreaming [stream url] [message]");

                    return;
                }

                IActivity activity = new StreamingGame(activityMessage, streamUrl);
                await DiscordBot.Bot.SetActivityAsync(activity);

                Configuration.UpdateConfiguration(activityName: activity.Name, activityType: (int)activity.Type, activityStream: streamUrl);

                AdminLog.Log(Context.User.Id, Context.Message.Content, Context.Guild.Id);
                var eb = new EmbedBuilder()
                         .WithDescription(Context.User.Username + " updated " + DiscordBot.Bot.CurrentUser.Mention + "'s activity message.")
                         .WithColor(Color.DarkGreen);

                await ReplyAsync("", false, eb.Build());
            }
        /// <summary>
        /// Discord Event Handler for when a Guild Member is updated from <paramref
        /// name="beforeGuildUser"/> to <paramref name="afterGuildUser"/>. This should only be
        /// processed for when a Member changes to "Streaming". Is used to notify a <c>Guild</c> if
        /// someone has a role we have been told to notify for.
        /// </summary>
        /// <param name="beforeGuildUser"></param>
        /// <param name="afterGuildUser"></param>
        /// <returns></returns>
        public async Task GuildMemberUpdated(SocketGuildUser beforeGuildUser, SocketGuildUser afterGuildUser)
        {
            if (afterGuildUser.Guild.Id != 225471771355250688)
            {
                return;
            }
            if (beforeGuildUser.IsBot || afterGuildUser.IsBot)
            {
                // I don't care about bots
                return;
            }
            // This will be where we trigger events such as when a user goes live in Discord to
            // check if the Guild has options enabled that allow notifying when people with a
            // certain role go live and verifying that it's a legit stream etc etc
            await Task.Delay(1);

            IActivity userActivity = afterGuildUser.Activity;

            if (userActivity == null)
            {
                return;
            }
            if (userActivity.Type == ActivityType.Streaming && userActivity is StreamingGame)
            {
                StreamingGame userGame = (StreamingGame)userActivity;
                //Log.Information($"User changed to Streaming {afterGuildUser.Username}#{afterGuildUser.DiscriminatorValue} {userGame.Name} {userGame.Url}");

                foreach (SocketRole role in afterGuildUser.Roles)
                {
                    if (role.IsEveryone)
                    {
                        continue;
                    }
                    //Log.Information($"{role.Id} {role.Name}");
                }
            }
            return;
        }
Пример #4
0
 internal void RaiseDiscordUserStartStream(BotChannel bChan, UserEntry user, StreamingGame streaminfo)
 {
     OnDiscordUserStartStream?.Invoke(bChan, user, streaminfo);
 }
Пример #5
0
        // Below needs to be verified
        internal async Task RaiseDiscordUserUpdated(SocketUser arg1, SocketUser arg2)
        {
            if (arg1 == null || arg1 == null)
            {
                await Core.LOG(new LogEntry(LOGSEVERITY.ERROR, "Events", "RaiseDiscordUserUpdated fed NULL parameter."));

                return;
            }
            if (arg1.IsBot)
            {
                return;
            }
            if (arg2.Activity == null)
            {
                return;
            }
            if (arg1.Activity == null)
            {
                return;
            }
            if (arg1.Activity.Type == ActivityType.Streaming)
            {
                if (arg2.Activity.Type != ActivityType.Streaming)
                {
                    // Discord users drops streaming flag
                    AddRefreshStamp(new GenericTimeStamp()
                    {
                        ulongID = arg1.Id, stringID = string.Empty, timestamp = Core.CurrentTime
                    });
                }
                return;
            }
            if (arg2.Activity.Type == ActivityType.Streaming)
            {
                if (CheckStamp(arg1.Id))
                {
                    foreach (SocketGuild guild in arg1.MutualGuilds)
                    {
                        BotChannel bChan = await Program.Channels.GetDiscordGuildbyID(guild.Id);

                        if (bChan == null)
                        {
                            return;
                        }
                        UserEntry user = await Program.Users.GetUserByDiscordID(arg1.Id);

                        if (user == null)
                        {
                            return;
                        }
                        StreamingGame stream = arg2.Activity as StreamingGame;
                        if (stream == null)
                        {
                            return;
                        }
                        //await Core.LOG(new LogMessage(LogSeverity.Error, "Events", $"RaiseDiscordUserUpdated {arg2.Username} StreamingGame. Stream.Name={stream.Name}, Stream.Type={stream.Type}, Stream.Url={stream.Url}"));
                        RaiseDiscordUserStartStream(bChan, user, stream);
                    }
                }
                return;
            }
        }
Пример #6
0
        internal static async Task Ready()
        {
            if (Configuration.Load().ActivityStream == null)
            {
                IActivity activity = new Game(Configuration.Load().ActivityName, (ActivityType)Configuration.Load().ActivityType);
                await DiscordBot.Bot.SetActivityAsync(activity);
            }
            else
            {
                IActivity activity = new StreamingGame(Configuration.Load().ActivityName, Configuration.Load().ActivityStream);
                await DiscordBot.Bot.SetActivityAsync(activity);
            }
            await DiscordBot.Bot.SetStatusAsync(Configuration.Load().Status);


            ModeratorModule.ActiveForDateTime = DateTime.Now;


            List <ulong> guildsInDatabase = new List <ulong>();
            var          dataReader       = DatabaseActivity.ExecuteReader("SELECT * FROM guilds;").Item1;

            while (dataReader.Read())
            {
                ulong id = dataReader.GetUInt64("guildID");
                guildsInDatabase.Add(id);
            }


            await new LogMessage(LogSeverity.Info, "Startup", "-----------------------------------------------------------------").PrintToConsole();
            foreach (SocketGuild g in DiscordBot.Bot.Guilds)
            {
                Console.ResetColor();
                await new LogMessage(LogSeverity.Info, "Startup", "Attempting to load " + g.Name).PrintToConsole();

                await GuildHandler.InsertGuildToDB(g);

                guildsInDatabase.Remove(g.Id);
                await new LogMessage(LogSeverity.Info, "Startup", "-----------------------------------------------------------------").PrintToConsole();

                foreach (SocketGuildChannel c in g.Channels)
                {
                    await ChannelHandler.InsertChannelToDB(c);
                }
                await new LogMessage(LogSeverity.Info, "Startup", "-----------------------------------------------------------------").PrintToConsole();

                await ReadyAddUsersToDatabase(g).ConfigureAwait(false);

                await new LogMessage(LogSeverity.Info, "Startup", "-----------------------------------------------------------------").PrintToConsole();

                await ReadyAddBansToDatabase(g).ConfigureAwait(false);

                Methods.PrintConsoleSplitLine();
            }

            foreach (ulong id in guildsInDatabase)
            {
                await GuildHandler.RemoveGuildFromDB(id.GetGuild());

                DatabaseActivity.ExecuteNonQueryCommand("DELETE FROM channels WHERE inGuildID=" + id);
                Console.WriteLine(id + @" has been removed from the database.");
            }

            await LoadAllFromDatabase();

            await new LogMessage(LogSeverity.Info, "Startup", DiscordBot.Bot.CurrentUser.Username + " loaded.").PrintToConsole();

            // Send message to log channel to announce bot is up and running.
            Version      v  = Assembly.GetExecutingAssembly().GetName().Version;
            EmbedBuilder eb = new EmbedBuilder();

            eb.WithTitle("Startup Notification");
            eb.WithColor(59, 212, 50);
            eb.WithThumbnailUrl(DiscordBot.Bot.CurrentUser.GetAvatarUrl());

            eb.AddField("Bot Name", DiscordBot.Bot.CurrentUser.Username + "#" + DiscordBot.Bot.CurrentUser.Discriminator, true);
            try
            {
                eb.AddField("Developer Name",
                            Configuration.Load().Developer.GetUser().Username + "#" +
                            Configuration.Load().Developer.GetUser().Discriminator, true);
            }
            catch (UserNotFoundException exception)
            {
                eb.AddField("Developer Name", "Melissa", true);
                await new LogMessage(LogSeverity.Warning, "Startup", exception.Message + " - Using \"Melissa\" instead.").PrintToConsole();
            }
            eb.AddField("Developer ID", Configuration.Load().Developer, true);

            eb.AddField("DiscordBot Version", "v" + v, true);
            eb.AddField("MelissaNET Version", "v" + VersionInfo.Version, true);
            eb.AddField(".NET Version", typeof(string).Assembly.ImageRuntimeVersion, true);

            eb.AddField("Connection & Server Information",
                        "**Latency:** " + DiscordBot.Bot.Latency + "ms" + "\n" +
                        "**Server Time:** " + DateTime.Now.ToString("h:mm:ss tt") + "\n");

            eb.AddField("Awards", Award.Awards.Count, true);
            eb.AddField("Quotes", Quote.Quotes.Count, true);
            eb.AddField("Quote Requests", RequestQuote.RequestQuotes.Count, true);

            eb.WithCurrentTimestamp();
            eb.WithFooter("Ready event executed");
            await Configuration.Load().LogChannelId.GetTextChannel().SendMessageAsync("", false, eb.Build());

            await NewUsersOfflineAlert();
        }