Exemplo n.º 1
0
        public static async Task LeftGuild(SocketGuild socketGuild)
        {
            foreach (SocketGuildChannel c in socketGuild.Channels)
            {
                await ChannelHandler.RemoveChannelFromDB(c);
            }

            await RemoveGuildFromDB(socketGuild).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public static async Task JoinedGuild(SocketGuild socketGuild)
        {
            await InsertGuildToDB(socketGuild).ConfigureAwait(false);

            foreach (SocketGuildChannel c in socketGuild.Channels)
            {
                await ChannelHandler.InsertChannelToDB(c);
            }

            await Configuration.Load().LogChannelId.GetTextChannel().SendMessageAsync(socketGuild.Name + " has been added to " + DiscordBot.Bot.CurrentUser.Username + "'s guild list. \n" + socketGuild.Owner.Username + " is the owner (" + socketGuild.Owner.Id + ")");

            await new LogMessage(LogSeverity.Info, "JoinedGuild", "[" + socketGuild.Name + "] " + "[@" + socketGuild.Owner.Username +
                                 "] : Bot Joined the Guild").PrintToConsole();
        }
Exemplo n.º 3
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();
        }