public async Task epsilonHelp() { IGuildUser activeuser = Context.User as IGuildUser; var epsilonmode = Justibot.Loader.LoadPerm(activeuser, "EPSILON"); if (epsilonmode.Item1 == true) { var Prefix = PrefixService.getPrefix(Context.Guild.Id); string message = ( $"{Prefix} {Format.Bold("whatASave:")} Returns random message (command won by Storm!) \n" + $"{Prefix} {Format.Bold("Tree:")} Shows a picture of a tree (Storm/Revan Joke) Requested by Storm \n" + $"{Prefix} {Format.Bold("penis:")} Try it and find out ;) \n" + $"{Prefix} {Format.Bold("jesus:")} Summons a representation of Jesus Christ under the request of Rohan \n" + $"{Prefix} {Format.Bold("Wisdom:")} Enlightens channel with the daily wisdom of Mike Nolan \n" + $"{Prefix} {Format.Bold("Toetem:")} shows the first Epsilon God to reveal itself" ); string message2 = ( $"{Format.Bold($"{Format.Underline("Prefix:")} {Prefix}")}" ); Color color = new Color(0, 225, 100); var embed = new EmbedBuilder() .WithTitle("Commands:") .WithColor(color) .AddField(x => { x.Name = "Current Prefix:"; x.Value = message2; x.WithIsInline(true); }) .AddField(x => { x.Name = "Basic:"; x.Value = message; x.WithIsInline(true); }) .Build(); await Context.Channel.SendMessageAsync("", false, embed); } }
public async Task giveHelp() { char Prefix = '+'; if (Context.Guild != null) { Prefix = PrefixService.getPrefix(Context.Guild.Id); } string message = ( $"{Prefix} {Format.Bold("`giveaway new <prize>`:")} Creates a new giveaway for the <prize> (user becomes host) \n" + $"{Prefix} {Format.Bold("`giveaway finish`:")} Ends the Giveaway (does not draw, must be used by host). \n" + $"{Prefix} {Format.Bold("`giveaway enter`:")} Enters user into the giveaway. \n" + $"{Prefix} {Format.Bold("`giveaway draw`:")} Draws the giveaway. \n" + $"{Prefix} {Format.Bold("`giveaway drawall <mode> (optional prize)`:")} randomly selects member who matches mode (online/offline/active/offline). \n" + $"{Prefix} {Format.Bold("`giveaway clear`:")} Clears all entries from the giveaway apart from the host. \n" + $"{Prefix} {Format.Bold("`giveaway details`:")} Shows the host, number of entries and prize." ); string message2 = ( $"{Format.Bold($"{Format.Underline("Prefix:")} {Prefix}")}" ); Color color = new Color(0, 225, 100); var embed = new EmbedBuilder() .WithTitle("Commands:") .WithColor(color) .AddField(x => { x.Name = "Current Prefix:"; x.Value = message2; x.WithIsInline(true); }) .AddField(x => { x.Name = "Commands:"; x.Value = message; x.WithIsInline(true); }) .Build(); await Context.Channel.SendMessageAsync("", false, embed); }
public void GivenSameHour_ThenSingleResultAllTheWayToHours() { // Actual var blobs = new List <CloudBlockBlob> { new CloudBlockBlob(new Uri("https://domain.blob.core.windows.net/container/prefix/2018/06/20/04/e872fe-35920.applicationLog.csv")), new CloudBlockBlob(new Uri("https://domain.blob.core.windows.net/container/prefix/2018/06/20/05/e872fe-35921.applicationLog.csv")), new CloudBlockBlob(new Uri("https://domain.blob.core.windows.net/container/prefix/2018/06/20/05/e872fe-35922.applicationLog.csv")), new CloudBlockBlob(new Uri("https://domain.blob.core.windows.net/container/prefix/2018/06/20/05/e872fe-35923.applicationLog.csv")), new CloudBlockBlob(new Uri("https://domain.blob.core.windows.net/container/prefix/2018/06/20/06/e872fe-35924.applicationLog.csv")), new CloudBlockBlob(new Uri("https://domain.blob.core.windows.net/container/prefix/2018/06/20/07/e872fe-35925.applicationLog.csv")) }; var from = new DateTime(2018, 6, 20, 5, 4, 3, DateTimeKind.Utc); var to = new DateTime(2018, 6, 20, 6, 6, 5, DateTimeKind.Utc); // Act var actualBlobs = PrefixService.Filter(blobs, from, to, "prefix/"); // Assert var expectedNames = new List <string> { "prefix/2018/06/20/05/e872fe-35921.applicationLog.csv", "prefix/2018/06/20/05/e872fe-35922.applicationLog.csv", "prefix/2018/06/20/05/e872fe-35923.applicationLog.csv", "prefix/2018/06/20/06/e872fe-35924.applicationLog.csv" }; actualBlobs.Select(q => q.Name).Should().BeEquivalentTo(expectedNames); }
public void GivenMultipleYears_ThenYearOfFromDateAndYearOfToDateAndAllYearsInBetween() { // Arrange var from = new DateTime(2018, 12, 31, 23, 55, 15, DateTimeKind.Utc); var to = from.AddYears(5); // Act var actual = PrefixService.BuildBlobPrefixes(from, to, Prefix); // Assert var expected = new List <string> { $"{Prefix}2018", $"{Prefix}2019", $"{Prefix}2020", $"{Prefix}2021", $"{Prefix}2022", $"{Prefix}2023" }; actual.Should().BeEquivalentTo(expected); }
/// <summary> /// Initializes a new instance of the <see cref="Inspections"/> class. /// </summary> /// <param name="service"> /// The service. /// </param> /// <param name="partnerService"> /// The partner Service. /// </param> /// <param name="prefix"> /// The prefix. /// </param> /// <param name="limits"> /// The limits. /// </param> public Inspections(TimerService service, PartnerService partnerService, PrefixService prefix, TranslateLimitsNew limits) { timerService = service; prefixService = prefix; PartnerService = partnerService; Limits = limits; }
public async Task levelHelp() { char Prefix = '+'; if (Context.Guild != null) { Prefix = PrefixService.getPrefix(Context.Guild.Id); } string message = ( $"{Prefix} {Format.Bold("Rank:")} Shows a users rank on the server (tag someone to see their rank) \n" + $"{Prefix} {Format.Bold("Rank Global:")} Shows a users global rank (tag someone to see their rank) \n" + $"{Prefix} {Format.Bold("Rank Server:")} See the servers ranking ;) \n" + $"{Prefix} {Format.Bold("Leaderboard:")} See the servers top 10 users. \n" + $"{Prefix} {Format.Bold("Leaderboard Global:")} See the top 10 users. \n" + $"{Prefix} {Format.Bold("Leaderboard Server:")} See the top 10 servers. \n\n" + $"{Prefix} {Format.Bold("Note:")} Server and user xp will not work unless the levels module is enabled." ); string message2 = ( $"{Format.Bold($"{Format.Underline("Prefix:")} {Prefix}")}" ); Color color = new Color(0, 225, 100); var embed = new EmbedBuilder() .WithTitle("Commands:") .WithColor(color) .AddField(x => { x.Name = "Current Prefix:"; x.Value = message2; x.WithIsInline(true); }) .AddField(x => { x.Name = "Commands:"; x.Value = message; x.WithIsInline(true); }) .Build(); await Context.Channel.SendMessageAsync("", false, embed); }
/// <summary> /// Initializes a new instance of the <see cref="Developer"/> class. /// </summary> /// <param name="service"> /// The service. /// </param> /// <param name="partnerService"> /// The partner Service. /// </param> /// <param name="prefix"> /// The prefix. /// </param> /// <param name="httpClient"> /// The http Client. /// </param> /// <param name="limits"> /// The limits. /// </param> public Developer(TimerService service, PartnerService partnerService, PartnerHelper pHelper, IDocumentStore store, PrefixService prefix, HttpClient httpClient, TranslateLimitsNew limits, DBLApiService dblApi) { timerService = service; prefixService = prefix; PartnerService = partnerService; docStore = store; client = httpClient; Limits = limits; PartnerHelper = pHelper; DblApi = dblApi; }
public CommandHandler(IServiceProvider provider) { Provider = provider; Client = provider.GetService <DiscordSocketClient>(); Config = provider.GetService <Config>(); Client.MessageReceived += ProcessCommandAsync; Commands = provider.GetService <CommandService>(); BaseModules = new Dictionary <Type, ModuleInfo>(); CleverbotAPI = new Cleverbot(Config.CleverbotApiKey); PrefixService = provider.GetService <PrefixService>(); }
public async Task Help() { char Prefix = '+'; if (Context.Guild != null) { Prefix = PrefixService.getPrefix(Context.Guild.Id); } string message = ( $"{Format.Bold($"{Format.Underline("Prefix:")} {Prefix}")}" ); string message1 = ( $"{Prefix} {Format.Bold("Ping:")} Returns Pong! \n" + $"{Prefix} {Format.Bold("Echo:")} Repeats what you say. \n" + $"{Prefix} {Format.Bold("Dice:")} Rolls a dice with a set amount of sides. Minimum 2, maximum 255, leave blank for 6. \n" + $"{Prefix} {Format.Bold("Coin:")} Coin toss." ); string message2 = ( $"{Prefix} {Format.Bold("Kick/Ban:")} Kicks/Bans a user from the server. \n" + $"{Prefix} {Format.Bold("Purge x:")} Deletes x amount of messages from a channel. (25 by default, 100 max) \n" + $"{Prefix} {Format.Bold("Mute/Unmute:")} Mutes/Unmutes a user in the server." ); string message3 = ( $"{Prefix} {Format.Bold("Info:")} Displays bots info. \n" + $"{Prefix} {Format.Bold("Userinfo:")} Returns information on mentioned user, leave blank for yourself. (username ID and time created) \n" + $"{Prefix} {Format.Bold("Serverinfo:")} Returns information on the server." ); string message4 = ( $"{Prefix} {Format.Bold("Documentation:")} [http://tatenashi.com](http://tatenashi.com) \n" + $"{Prefix} {Format.Bold("Official Server:")} [https://discord.gg/gS6zZ3B](https://discord.gg/gS6zZ3B) \n" + $"{Prefix} {Format.Bold("Contact:")} [http://tatenashi.com/home/contact](http://tatenashi.com/home/contact)" ); string message5 = ( $"{Prefix} {Format.Bold("Help notes:")} Help for notes module. \n" + $"{Prefix} {Format.Bold("Help Ranks:")} Help for xp module " ); Color color = new Color(0, 225, 100); var embed = new EmbedBuilder() .WithTitle("Commands:") .WithColor(color) .AddField(x => { x.Name = "Current Prefix:"; x.Value = message; x.WithIsInline(true); }) .AddField(x => { x.Name = "Basic:"; x.Value = message1; x.WithIsInline(true); }) .AddField(x => { x.Name = "Moderator:"; x.Value = message2; x.WithIsInline(true); }) .AddField(x => { x.Name = "Info:"; x.Value = message3; x.WithIsInline(true); }) .AddField(x => { x.Name = "Other help commands:"; x.Value = message5; x.WithIsInline(true); }) .AddField(x => { x.Name = "Links:"; x.Value = message4; x.WithIsInline(true); }) .Build(); await Context.Channel.SendMessageAsync("", false, embed); }
public async Task prefix(char prefix) { var activeuser = Context.User as IGuildUser; var application = await Context.Client.GetApplicationInfoAsync(); if (activeuser.GuildPermissions.Has(GuildPermission.Administrator) || activeuser.Id == application.Owner.Id) { PrefixService.addPrefixes(Context.Guild, prefix); Justibot.Saver.SavePrefix(activeuser, prefix); await ReplyAsync($"{Context.User.Mention}, set the prefix to {Format.Bold($"{prefix}")}"); } else { await ReplyAsync("You do not have permission to use this command"); } }
public async Task Gnew(IUser host, [Remainder] string prize) { var activeuser = host as IGuildUser; var prefix = PrefixService.getPrefix(Context.Guild.Id); var application = await Context.Client.GetApplicationInfoAsync(); var activator = true; var gives = Justibot.Loader.LoadGiveaway(activeuser); var results = Justibot.Loader.LoadPerm(activeuser, "GIVEAWAY"); ITextChannel channel = await Context.Guild.GetTextChannelAsync(results.Item2) as ITextChannel; ulong channel2 = (await Context.Guild.GetTextChannelAsync(gives.Item2) as ITextChannel).Id; if (Context.Channel.Id == results.Item2) { if (gives.Item1 == true) { await ReplyAsync("giveaway already in progress, cannot start a new one."); } else { if (results.Item1 == true) { if (results.Item3 == "OPEN") { Justibot.Saver.SaveGiveaway(activeuser, prize, activator, results.Item2); await channel.SendMessageAsync($"{activeuser.Mention} has started a giveaway for {Format.Bold($"{prize}!!!")} Use `{prefix}giveaway enter` to be in to win!!! \n" + $"Host ({activeuser.Mention}) is entered by default"); } else if (results.Item3 == "CLOSED" && (activeuser.GuildPermissions.Has(GuildPermission.ManageGuild) || application.Owner == Context.User)) { Justibot.Saver.SaveGiveaway(activeuser, prize, activator, channel.Id); await channel.SendMessageAsync($"{activeuser.Mention} has started a giveaway for {Format.Bold($"{prize}!!!")} Use `{prefix}giveaway enter` to be in to win!!! \n" + $"Host ({activeuser.Mention}) is entered by default"); } else { await ReplyAsync("you do not have permission to do start a giveaway."); } } else { await ReplyAsync("giveaways are currently not enabled."); } } } }
public async Task notesHelp() { char Prefix = '+'; if (Context.Guild != null) { Prefix = PrefixService.getPrefix(Context.Guild.Id); } string message = ( $"{Prefix} {Format.Bold("`notes new <type> <noteName> <note content>`:")} Creates a new note of type <type> \n" + $"{Prefix} {Format.Bold("`notes view (user)`:")} Shows a users public notes, if left blank shows all notes associated with user. \n" + $"{Prefix} {Format.Bold("`notes close`:")} deletes last note the user has viewed ;) \n" + $"{Prefix} {Format.Bold("`notes delete <noteId>`:")} deletes the associated note if the user owns it. \n" + $"{Prefix} {Format.Bold("`notes admindelete <noteId>`:")} deletes a server not if user has manage server permission." ); string message2 = ( $"{Format.Bold($"{Format.Underline("Prefix:")} {Prefix}")}" ); string message3 = ( "A user can have 10 public and private notes \n" + "A server can have 30 server notes and 20 staff notes \n" + "A note title must be one word with a 25 character limit any words after this will be added to the note \n" + "A notes content has a 150 character limit and can contain multiple words." ); string message4 = ( $"{Prefix} {Format.Bold("Public:")} Any user can view this note, only the owner may delete it. \n" + $"{Prefix} {Format.Bold("Private:")} Only the owner can view this note, only the owner may delete it. \n" + $"{Prefix} {Format.Bold("Server:")} Any user on the server can view this note, only the owner or a staff member may delete it. \n" + $"{Prefix} {Format.Bold("Staff:")} Any user on the server can view this note, only the owner or a staff member may delete it. \n\n" + $"{Prefix} {Format.Bold("Note:")} If the notes module is set to closed only staff can create server notes, if it is open anyone may create these notes." ); Color color = new Color(0, 225, 100); var embed = new EmbedBuilder() .WithTitle("Commands:") .WithColor(color) .AddField(x => { x.Name = "Current Prefix:"; x.Value = message2; x.WithIsInline(true); }) .AddField(x => { x.Name = "Commands:"; x.Value = message; x.WithIsInline(true); }) .AddField(x => { x.Name = "Note Types:"; x.Value = message4; x.WithIsInline(true); }) .AddField(x => { x.Name = "Limits:"; x.Value = message3; x.WithIsInline(true); }) .Build(); await Context.Channel.SendMessageAsync("", false, embed); }
public async Task MatchesAsync(string prefix) { var mockTrigger = new Mock <ITrigger>(); mockTrigger.Setup(x => x.CheckTriggerAsync(It.IsAny <IContext>())) .Returns(Task.FromResult(prefix)); var service = new PrefixService( new PrefixCollectionBuilder() .AddAsDefault(mockTrigger.Object) .Build()); var mock = new Mock <IContext>(); var result = await service.MatchAsync(mock.Object); Assert.Equal(prefix, result); }
/// <summary> /// Initializes a new instance of the <see cref="EventHandler"/> class. /// </summary> /// <param name="client"> /// The client. /// </param> /// <param name="homeService"> /// The home Service. /// </param> /// <param name="config"> /// The config. /// </param> /// <param name="service"> /// The service. /// </param> /// <param name="levels"> /// The levels. /// </param> /// <param name="channelHelper"> /// The channel Helper. /// </param> /// <param name="commandService"> /// The command service. /// </param> /// <param name="prefixService"> /// The prefix Service. /// </param> public EventHandler(DiscordShardedClient client, TranslateLimitsNew limits, WaitService waits, DBLApiService dblService, TranslateMethodsNew translationMethods, TranslationService translationService, HomeService homeService, ConfigModel config, IServiceProvider service, LevelHelper levels, ChannelHelper channelHelper, CommandService commandService, PrefixService prefixService) { Client = client; Config = config; Provider = service; CommandService = commandService; prefixOverride = DatabaseHandler.Settings.UsePrefixOverride; PrefixService = prefixService; _ChannelHelper = channelHelper; _LevelHelper = levels; _HomeService = homeService; _Translate = translationService; Limits = limits; Waits = waits; TranslationMethods = translationMethods; DBLApi = dblService; CancellationToken = new CancellationTokenSource(); }
public void Given60MinutesOrMoreDifferenceButLessThanDay_ThenAllTheWayToDay() { // Arrange var from = new DateTime(2018, 10, 6, 16, 7, 3, DateTimeKind.Utc); var to = from.AddMinutes(65); // Act var actual = PrefixService.BuildBlobPrefixes(from, to, Prefix); // Assert var expected = new List <string> { $"{Prefix}2018/10/06" }; actual.Should().BeEquivalentTo(expected); }
public void Given28DayOrMoreMoreButLessThanYear_ThenAllTheWayToYear() { // Arrange var from = new DateTime(2018, 10, 6, 16, 7, 3, DateTimeKind.Utc); var to = from.AddDays(29); // Act var actual = PrefixService.BuildBlobPrefixes(from, to, Prefix); // Assert var expected = new List <string> { $"{Prefix}2018" }; actual.Should().BeEquivalentTo(expected); }
public void GivenSameHour_ThenSingleResultAllTheWayToHours() { // Arrange var from = new DateTime(2018, 10, 6, 16, 7, 3, DateTimeKind.Utc); var to = from.AddMinutes(10); // Act var actual = PrefixService.BuildBlobPrefixes(from, to, Prefix); // Assert var expected = new List <string> { $"{Prefix}2018/10/06/16" }; actual.Should().BeEquivalentTo(expected); }
public void Given60MinutesOrMoreDifferenceButLessThanDayAndDifferentYears_ThenLastDayOfFromYearAndFirstDayOfToYear() { // Arrange var from = new DateTime(2018, 12, 31, 23, 55, 15, DateTimeKind.Utc); var to = from.AddMinutes(65); // Act var actual = PrefixService.BuildBlobPrefixes(from, to, Prefix); // Assert var expected = new List <string> { $"{Prefix}2018/12/31", $"{Prefix}2019/01/01" }; actual.Should().BeEquivalentTo(expected); }
public void Given28DayOrMoreButLessThanYearAndDifferentYear_ThenYearOfFromDateAndYearOfToDate() { // Arrange var from = new DateTime(2018, 12, 31, 23, 55, 15, DateTimeKind.Utc); var to = from.AddDays(29); // Act var actual = PrefixService.BuildBlobPrefixes(from, to, Prefix); // Assert var expected = new List <string> { $"{Prefix}2018", $"{Prefix}2019" }; actual.Should().BeEquivalentTo(expected); }
public async Task GDetails() { var activeuser = Context.User as IGuildUser; var prefix = PrefixService.getPrefix(Context.Guild.Id); int entcount = Justibot.Loader.entrycount(activeuser); ulong hostID = Justibot.Loader.GetGHost(activeuser); var hoster = await Context.Guild.GetUserAsync(hostID) as IUser; var gives = Justibot.Loader.LoadGiveaway(activeuser); string prize = gives.Item3; ITextChannel channel = await Context.Guild.GetTextChannelAsync(gives.Item2) as ITextChannel; if (gives.Item1 == true) { await channel.SendMessageAsync($"{activeuser.Mention}, {hoster.Username} is hosting a giveaway for {Format.Bold($"{prize}!!!")} Use `{prefix}giveaway enter` to be in to win!!! currently {entcount} entries."); } else { await ReplyAsync("There are currently no giveaways running."); } }
public Task GoodbyeEventAsync() { var pre = PrefixService.GetPrefix(Context.Guild.Id); return(SimpleEmbedAsync("**Goodbye Event**\n" + $"`{pre}Goodbye Info` - This Message\n" + $"`{pre}Goodbye Toggle` - Toggle the Goodbye event\n" + $"`{pre}Goodbye SetChannel` - Set the channel where Goodbye events will be sent\n" + $"`{pre}Goodbye Message <Message>` - Set the Goodbye Message\n\n" + "**Goodbye Settings**\n" + $"Enabled: {Context.Server.Events.Goodbye.Enabled}\n" + $"Channel: {Context.Guild.GetChannel(Context.Server.Events.Goodbye.ChannelID)?.Name ?? "N/A"}\n" + "Message:\n" + $"{Context.Server.Events.Goodbye.Message ?? "N/A"}")); }
public async Task Start() { Configuration.configure(); //create client and add what serverity of information to log client = new DiscordSocketClient(new DiscordSocketConfig() { LogLevel = LogSeverity.Info, ExclusiveBulkDelete = false, }); //create template for logged messages client.Log += (message) => { Console.WriteLine(message.ToString()); return(Task.CompletedTask); }; //when client is ready, load important information to memory for quick access and set game to help message client.Ready += async() => { await client.SetGameAsync("Use +help"); PrefixService.LoadPrefixs(client); WelcomeService.LoadWelcomes(client); LeavingService.Loadleaving(client); XpService.Loadxps(client); //start timer for xp module XpService.timerStart(); //if version from data file has changed, reset update time (used to track time since update) if (Justibot.Loader.checkUpdate().Value != Justibot.Data.version) { Justibot.Saver.addVersion(DateTime.Now, Justibot.Data.version); } }; //log the client into discord with the bot token await client.LoginAsync(TokenType.Bot, Configuration.config.Token); await client.StartAsync(); //when a user joins a guild, check appropriate permissions and react accordingly client.UserJoined += async(user) => { //check welcome module var results = Justibot.Loader.LoadPerm(user, "WELCOME"); var guild = user.Guild as IGuild; //if welcome module enabled send message if (results.Item1 == true) { ulong result2 = results.Item2; //get designated channel for welcome messages SocketTextChannel welcomeChannel = user.Guild.GetChannel(result2) as SocketTextChannel; //if welcome message is available for guild use it, otherwise use default bool check = welcomedict.welcomes.TryGetValue(guild.Id, out string welcome); if (!check) { welcome = "Welcome, **[user]** has joined **[server]!!!** \n" + "Have a good time!!!"; } //fill in placeholder text with appropriate information welcome = welcome.Replace("[user]", user.Username); welcome = welcome.Replace("[server]", guild.Name); //if permission argument is plain send message in plain text otherwise send in embeded message if (results.Item3 == "PLAIN") { await welcomeChannel.SendMessageAsync(welcome); } else { string avatar = user.GetAvatarUrl(); if (avatar == null) { avatar = "https://cdn.discordapp.com/embed/avatars/0.png"; } Color color = new Color(0, 255, 0); if (avatar.Contains("/a_")) { avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128"; } var embed = new EmbedBuilder() .WithColor(color) .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}") .WithDescription(welcome) .WithThumbnailUrl(avatar) .Build(); await welcomeChannel.SendMessageAsync(user.Mention, false, embed); } } //if joining role is enabled give new user the role var joinRoles = Justibot.Loader.LoadPerm(user, "JOINROLE"); if (joinRoles.Item1 == true) { IRole joinerRole = user.Guild.GetRole(joinRoles.Item2) as IRole; await user.AddRoleAsync(joinerRole); } //if log permission enabled send message to log channel var results2 = Justibot.Loader.LoadPerm(user, "LOG"); if (results2.Item1 == true) { ulong result2 = results2.Item2; SocketTextChannel logChannel = user.Guild.GetChannel(result2) as SocketTextChannel; if (results2.Item3 == "PLAIN") { await logChannel.SendMessageAsync($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has joined the server. \n" + $"There are now {user.Guild.MemberCount} members."); } else { string avatar = user.GetAvatarUrl(); Color color = new Color(0, 255, 0); //if no avatar available use deafult if (avatar == null) { avatar = "https://cdn.discordapp.com/embed/avatars/0.png"; } //check if avatar is gif (gif avatars contain /a_ in their URLs if (avatar.Contains("/a_")) { avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128"; } var embed = new EmbedBuilder() .WithColor(color) .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}") .WithDescription($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has joined the server. \n" + $"There are now {user.Guild.MemberCount} members.") .WithThumbnailUrl(avatar) .Build(); await logChannel.SendMessageAsync("", false, embed); } } //if bunker mode is enabled on server instantly kick new user if (Settings.bunker.Contains(guild.Id)) { await user.Guild.DefaultChannel.SendMessageAsync($"{Format.Bold($"{user.Username}")} was kicked by bunker mode!"); await user.KickAsync("Bunker mode enabled"); } }; //when user leaves guild check appropriate permissions and act accordingly client.UserLeft += async(user) => { //check leaving permission var results = Justibot.Loader.LoadPerm(user, "LEAVING"); if (results.Item1 == true) { ulong result2 = results.Item2; var guild = user.Guild as IGuild; //get channel to send leaving message to SocketTextChannel leaveChannel = user.Guild.GetChannel(result2) as SocketTextChannel; //if leaving message available set it, else use default message bool check = welcomedict.leaves.TryGetValue(guild.Id, out string leave); if (!check) { leave = "**[mention]** has left **[server]**, goodbye."; } //replace placeholder text with appropriate items leave = leave.Replace("[user]", user.Username); leave = leave.Replace("[mention]", user.Mention); leave = leave.Replace("[server]", guild.Name); //if leaving permission argument is plain, send plain text otherwise send as an embed message if (results.Item3 == "PLAIN") { await leaveChannel.SendMessageAsync(leave); } else { string avatar = user.GetAvatarUrl(); Color color = new Color(255, 0, 0); //if no avatar available use deafult if (avatar == null) { avatar = "https://cdn.discordapp.com/embed/avatars/0.png"; } //check if avatar is gif (gif avatars contain /a_ in their URLs if (avatar.Contains("/a_")) { avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128"; } var embed = new EmbedBuilder() .WithColor(color) .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}") .WithDescription(leave) .WithThumbnailUrl(avatar) .Build(); await leaveChannel.SendMessageAsync("", false, embed); } } //if log module is enabled, send message to log channel bassed on argument (plain text or embed) var results2 = Justibot.Loader.LoadPerm(user, "LOG"); if (results2.Item1 == true) { ulong result2 = results2.Item2; var guild = user.Guild as IGuild; SocketTextChannel welcomeChannel = user.Guild.GetChannel(result2) as SocketTextChannel; if (results2.Item3 == "PLAIN") { await welcomeChannel.SendMessageAsync($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has left the server. \n" + $"There are now {user.Guild.MemberCount} members."); } else { string avatar = user.GetAvatarUrl(); Color color = new Color(255, 0, 0); //if no avatar available use deafult if (avatar == null) { avatar = "https://cdn.discordapp.com/embed/avatars/0.png"; } //check if avatar is gif (gif avatars contain /a_ in their URLs if (avatar.Contains("/a_")) { avatar = $"{avatar.Remove(avatar.Length - 12)}gif?size=128"; } var embed = new EmbedBuilder() .WithColor(color) .WithTitle($"{Format.Bold($"{client.CurrentUser.Username}:")}") .WithDescription($"{Format.Bold($"{user.Username}")}#{user.Discriminator}, ID:<{user.Id}> has left the server. \n" + $"There are now {user.Guild.MemberCount} members.") .WithThumbnailUrl(avatar) .Build(); await welcomeChannel.SendMessageAsync("", false, embed); } } }; //if user messages a channel the bot can see, check permissions client.MessageReceived += async(message) => { var guild = (message.Channel as SocketTextChannel)?.Guild; var user = (message.Author as IGuildUser); if (guild != null) { //if user isnt bot, give xp to user if (user.IsBot == false) { var guild2 = guild as IGuild; XpService.AddXp(user, guild2); } //if message contains a discord invite link, check if use has manage guild permissions if ((message.ToString().ToUpper()).Contains("DISCORD.GG/") && (!(user.IsBot))) { //if user does not have manage guild permission check if advertising module is enabled if (!(user.GuildPermissions.Has(GuildPermission.ManageGuild)) || !(Justibot.Loader.isStaff(user))) { var results = Justibot.Loader.LoadPerm(user, "ADVERTISING"); if (results.Item1 == true) { //if module is set to delete, remove message and asks user to not advertise in the server ulong result2 = results.Item2; if (results.Item3 == "DELETE") { await message.DeleteAsync(); var response = await message.Channel.SendMessageAsync($"{user.Mention} please do not advertise in this server"); respond(response); } //if module is set to repost, send copy of message to advertising channel and ask user to only post advertisements to channel else if (results.Item3 == "REPOST") { SocketTextChannel advertisingChannel = guild.GetChannel(result2) as SocketTextChannel; if (message.Channel != advertisingChannel) { await advertisingChannel.SendMessageAsync($"{user.Mention} advertised message: \n{message.ToString()}"); await message.DeleteAsync(); var response = await message.Channel.SendMessageAsync($"{user.Mention} please keep advertising to {advertisingChannel.Mention}, your message has been shifted there."); respond(response); } } } } } } }; //initialize commands and commandhandler handler = new CommandHandler(); await handler.InitCommands(client); //prevent application shutdown await Task.Delay(-1); }
public EventSetup(PrefixService prefixService) { PrefixService = prefixService; }
/// <summary> /// This event is triggered every time the a user sends a Message in a channel, dm etc. that the bot has access to view. /// </summary> /// <param name="socketMessage"> /// The socket Message. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> internal async Task MessageReceivedAsync(SocketMessage socketMessage) { if (!(socketMessage is SocketUserMessage Message) || Message.Channel is IDMChannel) { return; } if (string.IsNullOrWhiteSpace(Message.Content) || Message.Content.Length < 3) { return; } if (Message.Author.IsBot || Message.Author.IsWebhook) { // Filter out all bot messages from triggering commands. return; } // Ensure that blacklisted users/guilds are not allowed to run commands if (CheckBlacklist(Message.Author.Id, (Message.Channel as IGuildChannel).Guild.Id)) { return; } await _ChannelHelper.DoMediaChannelAsync(Message); var argPos = 0; var isPrefixed = true; if (prefixOverride) { var config = JsonConvert.DeserializeObject <DatabaseObject>(File.ReadAllText("setup/DBConfig.json")); if (config.PrefixOverride != null) { if (!Message.HasStringPrefix(config.PrefixOverride, ref argPos)) { isPrefixed = false; } } else { LogHandler.LogMessage("Message Handler is being returned as the bot is in prefix override mode and you haven't specified a custom prefix in DBConfig.json", LogSeverity.Warning); isPrefixed = false; } } else { // Filter out all messages that don't start with our Bot PrefixSetup, bot mention or server specific PrefixSetup. if (!(Message.HasMentionPrefix(Client.CurrentUser, ref argPos) || Message.HasStringPrefix(PrefixService.GetPrefix((Message.Channel as IGuildChannel)?.Guild?.Id ?? 0), ref argPos))) { isPrefixed = false; } } // run level check and auto-message channel check if the current message is not a command prefixed message if (!isPrefixed) { var messageTask = Task.Run( async() => { LogHandler.LogMessage($"G: {(Message.Channel as IGuildChannel)?.Guild?.Id} | C: {Message.Channel?.Id} | U: {Message.Author?.Id.ToString()} | M: {Message?.Content.Left(100)}", LogSeverity.Verbose); await _LevelHelper.DoLevelsAsync(Message); await _ChannelHelper.DoAutoMessageAsync(Message); }); await StatHelper.LogMessageAsync(Message); return; } // Here we attempt to execute a command based on the user Message var commandTask = Task.Run(async() => { var context = new Context(Client, Message, Provider); var result = await CommandService.ExecuteAsync(context, argPos, Provider, MultiMatchHandling.Best); // Generate an error Message for users if a command is unsuccessful if (!result.IsSuccess) { await CmdErrorAsync(context, result, argPos); } else { var search = CommandService.Search(context, argPos); var cmd = search.Commands.FirstOrDefault(); StatHelper.LogCommand(cmd.Command, Message); if (Config.LogCommandUsages) { LogHandler.LogMessage(context); } } }); }
public GeneralSetup(PrefixService prefixService) { PrefixService = prefixService; }
public Partner(PrefixService prefixService, PartnerService partnerService, PartnerHelper partnerHelper) { PrefixService = prefixService; PartnerService = partnerService; PartnerHelp = partnerHelper; }
public Roles(PrefixService prefixService, WaitService wait) { PrefixService = prefixService; WaitService = wait; }
/// <summary> /// Initializes a new instance of the <see cref="Help" /> class. /// </summary> /// <param name="commandservice"> /// The commandservice. /// </param> /// <param name="prefixService"> /// The prefix Service. /// </param> private Help(CommandService commandservice, PrefixService prefixService) { service = commandservice; PrefixService = prefixService; }
public async Task UserJoined(SocketGuildUser user) { if (!LocalManagementService.LastConfig.IsAcceptable(user.Guild.Id)) { return; } var config = GetCaptchaConfig(user.Guild.Id); if (config.UseCaptcha) { var captchaDoc = GetOrCreateCaptchaUser(user.Id, user.Guild.Id); if (captchaDoc.Passed) { return; } var role = await GetOrCreateCaptchaRole(config, user.Guild); await user.AddRoleAsync(role); if (captchaDoc.FailureCount >= config.MaxFailures) { return; } var channel = await user.GetOrCreateDMChannelAsync(); if (channel == null) { return; } try { Stream imageStream = CaptchaGen.NetCore.ImageFactory.BuildImage(captchaDoc.Captcha, 100, 150, 25, 10, ImageFormatType.Jpeg); try { await user.SendFileAsync(imageStream, "captcha.jpg", $"Please run the Verify command in order to speak in {user.Guild.Name}. ie. `{PrefixService.GetPrefix(0)}Captcha Verify {user.Guild.Id} {captchaDoc.Captcha}`"); } catch { var guildChannel = user.Guild.GetTextChannel(config.ChannelId); if (guildChannel != null) { await guildChannel.SendFileAsync(imageStream, "captcha.jpg", $"{user.Mention} Please run the Verify command in order to speak in {user.Guild.Name}. ie. `{PrefixService.GetPrefix(user.Guild.Id)}Captcha Verify {user.Guild.Id} {captchaDoc.Captcha}`"); } } } catch { try { await user.SendMessageAsync($"Please run the Verify command in order to speak in {user.Guild.Name}. ie. `{PrefixService.GetPrefix(0)}Captcha Verify {user.Guild.Id} {captchaDoc.Captcha}`"); } catch { var guildChannel = user.Guild.GetTextChannel(config.ChannelId); if (guildChannel != null) { await guildChannel.SendMessageAsync($"Please run the Verify command in order to speak in {user.Guild.Name}. ie. `{PrefixService.GetPrefix(user.Guild.Id)}Captcha Verify {user.Guild.Id} {captchaDoc.Captcha}`"); } } } } }
public PrefixModule(PrefixService prefixService, EmbedService embedService, Config config, MathService mathService) : base(mathService) { PrefixService = prefixService; EmbedService = embedService; Config = config; }