private static async void EnsureConfigExists() { if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "data"))) { Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "data")); } var loc = Path.Combine(AppContext.BaseDirectory, "data/configuration.json"); if (!File.Exists(loc) || Configuration.Load().Token == null) { await NeoConsole.NewLine("Configuration not found...\nCreating...", ConsoleColor.Cyan); var config = new Configuration(); await NeoConsole.NewLine("Token :", ConsoleColor.DarkCyan); config.Token = Console.ReadLine(); await NeoConsole.NewLine("Default Prefix :", ConsoleColor.Cyan); config.Prefix = Console.ReadLine(); config.Save(); } else { await NeoConsole.NewLine("Configuration found...\nLoading...", ConsoleColor.Cyan); } }
public async Task Retard([Summary("User Mention")] IUser user = null) { try { var lastmessages = await Context.Channel.GetMessagesAsync(500, CacheMode.AllowDownload).FlattenAsync(); var userlast = lastmessages.Where(x => !x.Content.Contains("e.") && x.Author != Context.Client.CurrentUser).FirstOrDefault(x => x.Author == user); await Retard(userlast.Content); } catch (NullReferenceException) { await NeoConsole.Log(LogSeverity.Error, "FunModule", "Error getting last messages of user, outofcache"); } }
private async Task Run() { Console.OutputEncoding = Encoding.Unicode; await PrintInfoAsync(); using (var db = new NeoContext()) { db.Database.EnsureCreated(); } EnsureConfigExists(); _client = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Info, MessageCacheSize = 5000 }); await _client.LoginAsync(TokenType.Bot, Configuration.Load().Token); await NeoConsole.Append("Logging in...", ConsoleColor.Cyan); await _client.StartAsync(); await NeoConsole.NewLine("Success...", ConsoleColor.Cyan); _services = new ServiceCollection() .AddSingleton(_client) .AddSingleton <CommandHandler>() .AddSingleton <InteractiveService>() .BuildServiceProvider(); await NeoConsole.NewLine("Activating Services...\nDone.", ConsoleColor.Cyan); await _services.GetRequiredService <CommandHandler>().Install(_client, _services); await NeoConsole.NewLine("Command Handler starting...\nDone.\n", ConsoleColor.Cyan); _client.Log += Log; _client.Ready += _client_Ready; await Task.Delay(-1); }
private async Task HandleTag(SocketUserMessage e) { using (var db = new NeoContext()) { if (!db.Tags.Any(t => t.Trigger == e.Content)) { return; } var obj = db.Tags.FirstOrDefault(t => t.Trigger == e.Content); if (obj.IfAttachment) { await NeoConsole.Log(LogSeverity.Critical, "TAG", obj.Value); //await e.Channel.SendFileAsync(obj.Value,"henlo"); await e.Channel.SendMessageAsync("", false, NeoEmbeds.Picture(obj.Value, e.Author)); } else { await e.Channel.SendMessageAsync(obj.Value); } db.SaveChanges(); } }
private static async Task PrintInfoAsync() { var art = new[] { @"███████╗███████╗███████╗██████╗ ██████╗ ████████╗██████╗ ███████╗██████╗ ██╗ ██╗██╗ ██╗", @"██╔════╝██╔════╝╚══███╔╝██╔══██╗██╔═══██╗╚══██╔══╝██╔══██╗██╔════╝██╔══██╗██║ ██║╚██╗██╔╝", @"█████╗ █████╗ ███╔╝ ██████╔╝██║ ██║ ██║ ██████╔╝█████╗ ██║ ██║██║ ██║ ╚███╔╝ ", @"██╔══╝ ██╔══╝ ███╔╝ ██╔══██╗██║ ██║ ██║ ██╔══██╗██╔══╝ ██║ ██║██║ ██║ ██╔██╗ ", @"██║ ███████╗███████╗██████╔╝╚██████╔╝ ██║ ██║ ██║███████╗██████╔╝╚██████╔╝██╔╝ ██╗", @"╚═╝ ╚══════╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝", @" " }; foreach (var line in art) { await NeoConsole.NewLineArt(line, ConsoleColor.DarkMagenta); } await NeoConsole.Append("\n +-------------------------------------------------------------------------+", ConsoleColor.Gray); await NeoConsole.Append("\n Source Code(Github Repo): https://github.com/EchelonDev/NeoKapcho/ ", ConsoleColor.Yellow); await NeoConsole.Append("\n Build with love by 48 | Powered by SQLite and EFCore ", ConsoleColor.Red); await NeoConsole.Append("\n +-------------------------------------------------------------------------+", ConsoleColor.Gray); }
private async Task HandleCommand(SocketMessage s) { var msg = s as SocketUserMessage; if (msg == null) { return; // Check if the received message is from a user. } var context = new SocketCommandContext(_client, msg); // Create a new command context. if (context.User.IsBot) { return; } var prefix = Configuration.Load().Prefix; using (var db = new NeoContext()) { if (!db.Users.Any(x => x.Id == msg.Author.Id)) //if user does net exist in database create it { var newobj = new DbUser { Id = msg.Author.Id, Cash = 500 }; db.Users.Add(newobj); db.SaveChanges(); } if (!(msg.Channel is ISocketPrivateChannel) && db.Guilds.Any(x => x.Id == (msg.Channel as IGuildChannel).GuildId)) { prefix = db.Guilds.FirstOrDefault(x => x.Id == (msg.Channel as IGuildChannel).GuildId).Prefix ?? Configuration.Load().Prefix; } if (db.Blacklist.Any(bl => bl.User == db.Users.FirstOrDefault(u => u.Id == context.User.Id))) { return; } } await CheckAfk(msg); await HandleTag(msg); await NeoConsole.Log(msg); var argPos = 0; // Check if the message has either a string or mention prefix. if (msg.HasStringPrefix(prefix, ref argPos) || msg.HasStringPrefix(Configuration.Load().Prefix, ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) { IResult result; // Try and execute a command with the given context. try { result = await _cmds.ExecuteAsync(context, argPos, _services); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { var embed = NeoEmbeds.Error(result.ErrorReason, context.User, result.Error != null ? result.Error.ToString() : "Error").Build(); await context.Channel.SendMessageAsync("", false, embed); } } catch (Exception ex) { var embed = NeoEmbeds.Minimal(ex.Message).AddField("inner", ex.InnerException?.Message ?? "nope"); await NeoConsole.NewLine(ex.StackTrace); await context.Channel.SendMessageAsync("", false, embed.Build()); } } }
private static Task Log(LogMessage l) { Task.Run(async() => await NeoConsole.Log(l.Severity, l.Source, l.Exception?.ToString() ?? l.Message)); return(Task.CompletedTask); }