Exemplo n.º 1
0
        // all code here was used by Builderb's old Starboat source code (pls give him love <3)
        private async Task OnReactionAddedAsync(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (channel is SocketDMChannel || !reaction.User.IsSpecified || reaction.User.Value.IsBot || reaction.Emote.Name != _star)
            {
                return;
            }

            // get the values before doing anything
            var msg = await message.GetOrDownloadAsync();

            var chanID = _config["starboard:channelID"];

            // do some epic jeff
        }
Exemplo n.º 2
0
        private async Task Client_MessageDeleted(Cacheable <IMessage, ulong> message, ISocketMessageChannel channel)
        {
            SocketTextChannel textChannel = channel as SocketTextChannel;
            RestAuditLogEntry logEntry    = await GetAuditLogEntry(textChannel.Guild);

            if (logEntry.Action != ActionType.MessageDeleted)
            {
                return;
            }
            MessageDeleteAuditLogData data = (MessageDeleteAuditLogData)logEntry.Data;
            IUser user = await channel.GetUserAsync(data.AuthorId);

            string targetUsername = "******" + user + "** _(" + data.AuthorId + ")_";
            string adminUsername  = "******" + logEntry.User + "**";

            string msg = adminUsername + " deleted _" + data.MessageCount + "_ messages by " + targetUsername +
                         " in **#" + channel.Name + "** channel";

            foreach (SocketTextChannel chan in Global.SECURITY_CHANNELS)
            {
                if (chan.Guild.Id == textChannel.Guild.Id)
                {
                    if (!CheckPosted(logEntry, chan))
                    {
                        await SendSecurityLog(msg, new Color(255, 190, 0), chan, logEntry.Id.ToString(), logEntry.User.GetAvatarUrl());
                    }
                    break;
                }
            }
        }
Exemplo n.º 3
0
 public abstract Task Execute(ISocketMessageChannel channel, SocketUser user, params string[] args);
Exemplo n.º 4
0
 public JoinSideEvent(SocketUser author, ISocketMessageChannel postedChannel, bool isWhite)
 {
     Author        = author;
     PostedChannel = postedChannel;
     IsWhite       = isWhite;
 }
        internal new static SocketAutocompleteInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel, SocketUser user)
        {
            var entity = new SocketAutocompleteInteraction(client, model, channel, user);

            entity.Update(model);
            return(entity);
        }
Exemplo n.º 6
0
        private async Task HandleReactionAsync(Cacheable <IUserMessage, ulong> Message, ISocketMessageChannel Channel, SocketReaction Reaction)
        {
            var User = (SocketGuildUser)Reaction.User;

            if (User.IsBot)
            {
                return;
            }
            Leveling.UserAddedReaction(User, Reaction);
            await Task.CompletedTask;
        }
Exemplo n.º 7
0
 public GameProposal(SocketUser creator, ISocketMessageChannel channel, EmbededDrawer drawer)
 {
     Creator = creator;
     Channel = channel;
     Drawer  = drawer;
 }
Exemplo n.º 8
0
 // SendMessageAsync
 public static Task <RestUserMessage> SendMessageAsync(this ISocketMessageChannel channel, string text, bool isTTS, Embed embed, CancellationToken cancellationToken)
 => SendMessageAsync(channel, text, isTTS, embed, new RequestOptions {
     CancelToken = cancellationToken
 });
Exemplo n.º 9
0
 public static Task <RestUserMessage> SendMessageAsync(this ISocketMessageChannel channel, string text, CancellationToken cancellationToken)
 => SendMessageAsync(channel, text, false, null, cancellationToken);
Exemplo n.º 10
0
        public static IAsyncEnumerable <IReadOnlyCollection <IMessage> > GetMessagesAsync(ISocketMessageChannel channel, DiscordSocketClient discord, MessageCache messages,
                                                                                          ulong?fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
        {
            if (dir == Direction.Around)
            {
                throw new NotImplementedException(); //TODO: Impl
            }
            IReadOnlyCollection <SocketMessage> cachedMessages        = null;
            IAsyncEnumerable <IReadOnlyCollection <IMessage> > result = null;

            if (dir == Direction.After && fromMessageId == null)
            {
                return(AsyncEnumerable.Empty <IReadOnlyCollection <IMessage> >());
            }

            if (dir == Direction.Before || mode == CacheMode.CacheOnly)
            {
                if (messages != null) //Cache enabled
                {
                    cachedMessages = messages.GetMany(fromMessageId, dir, limit);
                }
                else
                {
                    cachedMessages = ImmutableArray.Create <SocketMessage>();
                }
                result = ImmutableArray.Create(cachedMessages).ToAsyncEnumerable <IReadOnlyCollection <IMessage> >();
            }

            if (dir == Direction.Before)
            {
                limit -= cachedMessages.Count;
                if (mode == CacheMode.CacheOnly || limit <= 0)
                {
                    return(result);
                }

                //Download remaining messages
                ulong?minId = cachedMessages.Count > 0 ? cachedMessages.Min(x => x.Id) : fromMessageId;
                var   downloadedMessages = ChannelHelper.GetMessagesAsync(channel, discord, minId, dir, limit, options);
                return(result.Concat(downloadedMessages));
            }
            else
            {
                if (mode == CacheMode.CacheOnly)
                {
                    return(result);
                }

                //Dont use cache in this case
                return(ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit, options));
            }
        }
Exemplo n.º 11
0
        public async Task TryRunCommand(SocketGuild guild, ISocketMessageChannel channel, IUserMessage usrMsg)
        {
            var execTime = Environment.TickCount;

            //its nice to have early blockers and early blocking executors separate, but
            //i could also have one interface with priorities, and just put early blockers on
            //highest priority. :thinking:
            foreach (var beh in _earlyBehaviors)
            {
                if (await beh.RunBehavior(_client, guild, usrMsg).ConfigureAwait(false))
                {
                    if (beh.BehaviorType == ModuleBehaviorType.Blocker)
                    {
                        Log.Information("Blocked User: [{0}] Message: [{1}] Service: [{2}]", usrMsg.Author,
                                        usrMsg.Content, beh.GetType().Name);
                    }
                    else if (beh.BehaviorType == ModuleBehaviorType.Executor)
                    {
                        Log.Information("User [{0}] executed [{1}] in [{2}]", usrMsg.Author, usrMsg.Content,
                                        beh.GetType().Name);
                    }

                    return;
                }
            }

            var exec2 = Environment.TickCount - execTime;


            string messageContent = usrMsg.Content;

            foreach (var exec in _inputTransformers)
            {
                string newContent;
                if ((newContent = await exec.TransformInput(guild, usrMsg.Channel, usrMsg.Author, messageContent)
                                  .ConfigureAwait(false)) != messageContent.ToLowerInvariant())
                {
                    messageContent = newContent;
                    break;
                }
            }
            var prefix          = GetPrefix(guild?.Id);
            var isPrefixCommand = messageContent.StartsWith(".prefix", StringComparison.InvariantCultureIgnoreCase);

            // execute the command and measure the time it took
            if (messageContent.StartsWith(prefix, StringComparison.InvariantCulture) || isPrefixCommand)
            {
                var(Success, Error, Info) = await ExecuteCommandAsync(new CommandContext(_client, usrMsg), messageContent, isPrefixCommand? 1 : prefix.Length, _services, MultiMatchHandling.Best).ConfigureAwait(false);

                execTime = Environment.TickCount - execTime;

                if (Success)
                {
                    await LogSuccessfulExecution(usrMsg, channel as ITextChannel, exec2, execTime).ConfigureAwait(false);
                    await CommandExecuted(usrMsg, Info).ConfigureAwait(false);

                    return;
                }
                else if (Error != null)
                {
                    LogErroredExecution(Error, usrMsg, channel as ITextChannel, exec2, execTime);
                    if (guild != null)
                    {
                        await CommandErrored(Info, channel as ITextChannel, Error).ConfigureAwait(false);
                    }
                }
            }
            else
            {
                await OnMessageNoTrigger(usrMsg).ConfigureAwait(false);
            }

            foreach (var exec in _lateExecutors)
            {
                await exec.LateExecute(_client, guild, usrMsg).ConfigureAwait(false);
            }
        }
Exemplo n.º 12
0
        private Task _client_ReactionAdded(Cacheable <IUserMessage, ulong> msg, ISocketMessageChannel chan, SocketReaction reaction)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    if (!reaction.User.IsSpecified ||
                        reaction.User.Value.IsBot ||
                        !(reaction.User.Value is SocketGuildUser gusr))
                    {
                        return;
                    }

                    if (!(chan is SocketGuildChannel gch))
                    {
                        return;
                    }

                    if (!_models.TryGetValue(gch.Guild.Id, out var confs))
                    {
                        return;
                    }

                    var conf = confs.FirstOrDefault(x => x.MessageId == msg.Id);

                    if (conf == null)
                    {
                        return;
                    }

                    var reactionRole = conf.ReactionRoles.FirstOrDefault(x => x.EmoteName == reaction.Emote.Name);
                    if (reactionRole != null)
                    {
                        if (conf.Exclusive)
                        {
                            var roleIds = conf.ReactionRoles.Select(x => x.RoleId)
                                          .Where(x => x != reactionRole.RoleId)
                                          .Select(x => gusr.Guild.GetRole(x))
                                          .Where(x => x != null);

                            var __ = Task.Run(async() =>
                            {
                                try
                                {
                                    //if the role is exclusive,
                                    // remove all other reactions user added to the message
                                    var dl = await msg.GetOrDownloadAsync().ConfigureAwait(false);
                                    foreach (var r in dl.Reactions)
                                    {
                                        if (r.Key.Name == reaction.Emote.Name)
                                        {
                                            continue;
                                        }
                                        try { await dl.RemoveReactionAsync(r.Key, gusr); } catch { }
                                        await Task.Delay(100).ConfigureAwait(false);
                                    }
                                }
                                catch { }
                            });
                            await gusr.RemoveRolesAsync(roleIds).ConfigureAwait(false);
                        }

                        var toAdd = gusr.Guild.GetRole(reactionRole.RoleId);
                        if (toAdd != null && !gusr.Roles.Contains(toAdd))
                        {
                            await gusr.AddRolesAsync(new[] { toAdd });
                        }
                    }
                    else
                    {
                        var dl = await msg.GetOrDownloadAsync().ConfigureAwait(false);
                        await dl.RemoveReactionAsync(reaction.Emote, dl.Author,
                                                     new RequestOptions()
                        {
                            RetryMode = RetryMode.RetryRatelimit | RetryMode.Retry502
                        });
                        _log.Warn("User {0} is adding unrelated reactions to the reaction roles message.", dl.Author);
                    }
                }
                catch { }
            });

            return(Task.CompletedTask);
        }
Exemplo n.º 13
0
        public static async void RenderImage(SocketUser user, ISocketMessageChannel channel)
        {
            RestUserMessage loader = await channel.SendMessageAsync("", false, LoadingMessage().Build());

            var    account  = UserInfoClasses.GetAccount(user);
            string username = Shorten_Long_Strings(user.Username, 32);

            //Establish other variables of the user's data
            string level             = $"{account.Level}";
            int    total_exp         = account.Total_Exp;
            string pmedals           = $"{account.P_Medals}";
            string proficiency_title = Core.LevelSystem.SocialStats.ProficiencyRankTitle(account.Proficiency_Rank);
            string diligence_title   = Core.LevelSystem.SocialStats.DiligenceRankTitle(account.Diligence_Rank);
            string expression_title  = Core.LevelSystem.SocialStats.ExpressionRankTitle(account.Expression_Rank);

            //Determine the Next Exp value
            int next_exp = 0;

            if (account.Level != 99)
            {
                next_exp = Core.LevelSystem.Leveling.CalculateExp(account.Level + 1) - account.Total_Exp;
            }

            Bitmap base_template = new Bitmap(template_width, template_height);

            Bitmap chara_bg   = (Bitmap)System.Drawing.Image.FromFile($@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//Profile//StatusScreens//Decor//Decor_TMS_Tsubasa_1//chara_bg.png");
            Bitmap ui_overlay = (Bitmap)System.Drawing.Image.FromFile($@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//Profile//StatusScreens//Decor//Decor_TMS_Tsubasa_1//ui_overlay.png");

            using (Graphics graphics = Graphics.FromImage(base_template))
            {
                graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

                graphics.DrawImage(chara_bg, 0, 0, template_width, template_height);
                graphics.DrawImage(ui_overlay, 0, 0, template_width, template_height);

                graphics.DrawImage(RenderFont(user, account), 0, 0, template_width, template_height);
                graphics.DrawImage(RenderLevelProgressBar(user), 0, 0, template_width, template_height);
                graphics.DrawImage(CombineSocialStatRankBitmaps(account), 0, 0, template_width, template_height);

                if (account.Level_Resets > 0)
                {
                    graphics.DrawImage(RenderPrestigeCounter(account.Level_Resets), 0, 0, template_width, template_height);
                }
            }

            MemoryStream memoryStream = new MemoryStream();

            base_template.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
            memoryStream.Seek(0, SeekOrigin.Begin);

            try
            {
                await channel.SendFileAsync(memoryStream, $"status_{user.Id}_{DateTime.UtcNow}.png");
            }
            catch (Exception ex)
            {
                _ = ErrorHandling.Scene_Upload_Failed(user, channel);
                Console.WriteLine(ex);

                memoryStream.Dispose();
                await loader.DeleteAsync();

                return;
            }

            memoryStream.Dispose();
            await loader.DeleteAsync();
        }
Exemplo n.º 14
0
        public async Task CheckEditedMessageAsync(Cacheable <IMessage, ulong> cacheable, SocketMessage s, ISocketMessageChannel channel)
        {
            if (!s.EditedTimestamp.HasValue)
            {
                return;
            }

            await CheckMessageAsync(s);
        }
Exemplo n.º 15
0
        private async Task _SocketClient_ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            if (arg3.UserId == this._Client.CurrentUser.Id ||
                arg3.User.Value.IsBot == true)
            {
                return;
            }

            ulong MainMsgID         = arg3.MessageId;
            ReactionRoleCommands Rc = new ReactionRoleCommands(this._Client);

            string SQL = "";

            switch (arg3.Emote.GetType().ToString())
            {
            case "Discord.Emoji":
                SQL = $@"select [role] FROM reaction_roles 
                            WHERE rmID = (SELECT rmID FROM reaction_messages WHERE messageID = {MainMsgID})
                            AND rID = (SELECT rID FROM reactions WHERE reaction_text = '{arg3.Emote.Name}')";
                break;

            case "Discord.Emote":
                SQL = $@"select [role] FROM reaction_roles 
                            WHERE rmID = (SELECT rmID FROM reaction_messages WHERE messageID = {MainMsgID})
                            AND rID = (SELECT rID FROM reactions WHERE reaction_text = '<:{(arg3.Emote as Emote).Name}:{(arg3.Emote as Emote).Id}>')";
                break;
            }

            using (SQLiteConnection conn = new SQLiteConnection(Support.DbConnectionString))
            {
                conn.Open();
                SQLiteCommand    Cmd    = new SQLiteCommand(SQL, conn);
                SQLiteDataReader Reader = Cmd.ExecuteReader();

                if (Reader.HasRows)
                {
                    Reader.Read();

                    var Chann = arg3.Channel as SocketGuildChannel;
                    var Guild = Chann.Guild;
                    var Role  = Guild.Roles.FirstOrDefault(x => x.Name == Reader.GetString(0));
                    if (Role != default(SocketRole))
                    {
                        var user = arg3.User.Value;
                        await(user as IGuildUser).AddRoleAsync(Role);
                    }
                }

                Reader.Close();
                Cmd.Dispose();
                conn.Close();
            }
        }
Exemplo n.º 16
0
 public static Task <RestUserMessage> SendMessageAsync(this ISocketMessageChannel channel, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null)
 => channel.SendMessageAsync(text, isTTS, embed, options);
Exemplo n.º 17
0
        private async Task OnMessageUpdatedAsync(Cacheable <IMessage, ulong> cached, SocketMessage message, ISocketMessageChannel channel)
        {
            var cachedMessage = await cached.GetOrDownloadAsync();

            if (Pattern.IsMatch(cachedMessage.Content))
            {
                return;
            }

            await OnMessageReceivedAsync(message);
        }
Exemplo n.º 18
0
        private async Task Client_ReactionAdded(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction reaction)
        {
            //////////////////
            // Check if bot //
            //////////////////

            if (reaction.User.IsSpecified && reaction.User.Value.IsBot)
            {
                return;
            }

            var reactionChannel = reaction.Channel as SocketGuildChannel;

            var reactionUser = reactionChannel.Guild.GetUser(reaction.UserId);

            if (reactionUser.IsBot)
            {
                return;
            }



            if
            (
                Vars.menuBuilder.IsActive &&
                Vars.menuBuilder.ChannelID == reaction.Channel.Id &&
                Vars.menuBuilder.UserID == reaction.UserId &&
                Vars.menuBuilder.CommandStep == 3
            )
            {
                Console.WriteLine("Launching GroupMenuEmojiAdder");
                MenuCreateMethods menuToCreate = new MenuCreateMethods();
                await menuToCreate.GroupMenuEmojiAdder(reaction);
            }
            else if
            (
                !Vars.menuBuilder.IsActive &&
                Vars.groupMenus.Any
                (
                    x => x.KinkMsgID == reaction.MessageId || x.LimitMsgID == reaction.MessageId
                )

            )
            {
                if (!reactionUser.Roles.Any(x => x.Name == "Sinners"))
                {
                    await reactionUser.SendMessageAsync("You may not use this menu until your intro is approved!");

                    return;
                }
                MenuAddMethods MenuAdding = new MenuAddMethods();
                await MenuAdding.KinkAdder(reaction);
            }



            //throw new NotImplementedException();
        }
Exemplo n.º 19
0
 async Task Client_MessageUpdated(Cacheable <IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3)
 {
     await filterMsg(arg2);
 }
Exemplo n.º 20
0
        private async Task Client_ReactionRemoved(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction reaction)
        {
            if (reaction.User.IsSpecified && reaction.User.Value.IsBot)
            {
                return;
            }

            var reactionChannel = reaction.Channel as SocketGuildChannel;

            var reactionUser = reactionChannel.Guild.GetUser(reaction.UserId);

            if (reactionUser.IsBot)
            {
                return;
            }


            if
            (
                !Vars.menuBuilder.IsActive &&
                Vars.groupMenus.Any
                (
                    x => x.KinkMsgID == reaction.MessageId || x.LimitMsgID == reaction.MessageId
                )

            )
            {
                if (!reactionUser.Roles.Any(x => x.Name == "Sinners"))
                {
                    await reactionUser.SendMessageAsync("You may not use this menu until your intro is approved!");

                    return;
                }
                MenuAddMethods MenuAdding = new MenuAddMethods();
                await MenuAdding.KinkRemover(reaction);
            }



            //throw new NotImplementedException();
        }
Exemplo n.º 21
0
 public JoinEvent(SocketUser author, ISocketMessageChannel postedChannel)
 {
     Author        = author;
     PostedChannel = postedChannel;
 }
Exemplo n.º 22
0
        public async Task PostSuperChat(ISocketMessageChannel channel, ulong fromId, ulong toId, int amount, string message, IDMChannel fromDmChannel, IDMChannel toDmChannel)
        {
            var fromMember = DbContext.VetMembers.FirstOrDefault(c => c.DiscordId == fromId);

            if (fromMember == null)
            {
                await fromDmChannel.SendMessageAsync("VetCoin 登録者以外はSuperChatを送信できません");

                return;
            }

            var fromAmount = CoreService.CalcAmount(fromMember);

            if (fromAmount < amount)
            {
                await fromDmChannel.SendMessageAsync($"VEC残高が不足しています。({fromAmount}VEC)");

                return;
            }

            if (amount < 100)
            {
                await fromDmChannel.SendMessageAsync($"送金下限は100VECです。それ未満は送れません");

                return;
            }


            if (amount > 50000)
            {
                await fromDmChannel.SendMessageAsync($"送金上限は50000VECです。それ以上は送れません");

                return;
            }

            var toMember = DbContext.VetMembers.FirstOrDefault(c => c.DiscordId == toId);

            if (toMember == null)
            {
                await fromDmChannel.SendMessageAsync("VetCoin 登録者以外へはSuperChatを送信できません");

                return;
                //toMember = DbContext.VetMembers.FirstOrDefault(c => c.DiscordId == 287434171570192384);
            }

            try
            {
                await fromDmChannel.SendMessageAsync($@"{toMember.Name}へ{amount}VEC 送金しました");

                await toDmChannel.SendMessageAsync($@"{fromMember.Name}から{amount}VEC をもらいました(SuperChat)");

                DbContext.CoinTransactions.Add(new CoinTransaction
                {
                    SendeVetMemberId   = fromMember.Id,
                    Amount             = amount,
                    RecivedVetMemberId = toMember.Id,
                    Text            = message,
                    TransactionType = CoinTransactionType.SuperChat,
                });
                await DbContext.SaveChangesAsync();
            }
            catch
            {
                await fromDmChannel.SendMessageAsync("システムトラブルの可能性があります。開発者に問い合わせをお願いします。");

                return;
            }

            try
            {
                var imageMs = await CreateImage(fromMember, toMember, amount);

                await channel.SendFileAsync(imageMs, $"Send{amount}.png", message);
            }
            catch
            {
                await fromDmChannel.SendMessageAsync("システムトラブルの可能性があります。開発者に問い合わせをお願いします。(送金は成功しています)");
            }
        }
        internal SocketAutocompleteInteraction(DiscordSocketClient client, Model model, ISocketMessageChannel channel, SocketUser user)
            : base(client, model.Id, channel, user)
        {
            var dataModel = model.Data.IsSpecified
                ? (DataModel)model.Data.Value
                : null;

            if (dataModel != null)
            {
                Data = new SocketAutocompleteInteractionData(dataModel);
            }
        }
Exemplo n.º 24
0
        private async Task _client_ReactionAdded(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            var amount = 0;

            if (arg3.Emote.Name == "10")
            {
                amount = 10;
            }

            if (arg3.Emote.Name == "50")
            {
                amount = 50;
            }

            if (amount == 0)
            {
                return;
            }

            var message = await arg2.GetMessageAsync(arg3.MessageId);

            var toId   = message.Author.Id;
            var fromId = arg3.UserId;

            //if(toId == fromId)
            //{
            //    return;
            //}

            IDMChannel fromDmChannel = null;

            if (arg3.User.IsSpecified)
            {
                fromDmChannel = await arg3.User.Value.GetOrCreateDMChannelAsync();
            }
            else
            {
                var user = await _rclient.GetUserAsync(fromId);

                fromDmChannel = await user.GetOrCreateDMChannelAsync();
            }
            var toDmChannel = await message.Author.GetOrCreateDMChannelAsync();



            using (var scope = Services.CreateScope())
            {
                var service = ActivatorUtilities.CreateInstance <ReactionSendService>(scope.ServiceProvider);
                await service.SendCoin(fromId, toId, amount, fromDmChannel, toDmChannel);
            }


            //arg2.GetMessageAsync()
            await Task.Yield();

            Console.WriteLine();
        }
Exemplo n.º 25
0
        private async Task Client_ReactionRemoved(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            if (arg3.Emote.Name != "⭐")
            {
                return;
            }
            using (var db = new DatabaseContext())
            {
                var smessages = db.StarredMessages.Where(x => x.GuildId == (arg2 as SocketGuildChannel).Guild.Id);
                if (smessages.Any(x => x.IsPinned && (x.MessageId == arg3.MessageId || x.StarboardMessageId == arg3.MessageId)))
                {
                    var setup     = db.GuildStarringSetups.FirstOrDefault(x => x.GuildId == (arg2 as SocketGuildChannel).Guild.Id);
                    var pin       = smessages.FirstOrDefault(x => x.MessageId == arg3.MessageId || x.StarboardMessageId == arg3.MessageId);
                    var starboard = client.GetGuild((arg2 as SocketGuildChannel).Guild.Id).GetTextChannel(setup.StarboardChannelId) as SocketTextChannel;

                    db.StarredMessages.FirstOrDefault(x => x.Id == pin.Id).Stars--;
                    db.StarredMessages.FirstOrDefault(x => x.Id == pin.Id).StarredByIds.Remove(arg3.UserId);

                    var pinmess = await starboard.GetMessageAsync(pin.StarboardMessageId);

                    await(pinmess as SocketUserMessage).ModifyAsync(x => x.Content = $"<#{pin.ChannelId}> ⭐{pin.Stars}");
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 26
0
        public async Task <Task> AddReactionHandeler(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            //Console.WriteLine(General.gameReaction);
            if (message.Id == General.gameReaction)
            {
                try
                {
                    if (channel is SocketTextChannel textChannel)
                    {
                        IRole role;
                        var   user = textChannel.Guild.GetUser(reaction.UserId);
                        switch (reaction.Emote.Name)
                        {
                        case "R6":
                            role = textChannel.Guild.GetRole(696784476172451863);
                            await user.AddRoleAsync(role);

                            break;

                        case "LOL":
                            role = textChannel.Guild.GetRole(724630435195256924);
                            await user.AddRoleAsync(role);

                            break;

                        case "AmongUS":
                            role = textChannel.Guild.GetRole(749651348584399008);
                            await user.AddRoleAsync(role);

                            break;

                        case "HumanFallFlat":
                            role = textChannel.Guild.GetRole(703006182020874270);
                            await user.AddRoleAsync(role);

                            break;

                        case "unnamed":
                            role = textChannel.Guild.GetRole(456454238801887232);
                            await user.AddRoleAsync(role);

                            break;

                        case "WOT":
                            role = textChannel.Guild.GetRole(456454276890230784);
                            await user.AddRoleAsync(role);

                            break;

                        case "GTAV":
                            role = textChannel.Guild.GetRole(456454320007938059);
                            await user.AddRoleAsync(role);

                            break;

                        case "PUBG":
                            role = textChannel.Guild.GetRole(456454619346763797);
                            await user.AddRoleAsync(role);

                            break;

                        case "Minecraft":
                            role = textChannel.Guild.GetRole(456454657410203649);
                            await user.AddRoleAsync(role);

                            break;

                        case "CS":
                            role = textChannel.Guild.GetRole(456454915104047116);
                            await user.AddRoleAsync(role);

                            break;

                        case "Forza":
                            role = textChannel.Guild.GetRole(698235330540863509);
                            await user.AddRoleAsync(role);

                            break;

                        case "Valorant":
                            role = textChannel.Guild.GetRole(728330936285921341);
                            await user.AddRoleAsync(role);

                            break;

                        case "Roblox":
                            role = textChannel.Guild.GetRole(728334339607101562);
                            await user.AddRoleAsync(role);

                            break;

                        case "Diablo":
                            role = textChannel.Guild.GetRole(728952822137225247);
                            await user.AddRoleAsync(role);

                            break;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                //var guild = client.GetGuild(Convert.ToUInt64(message.Value.Id));
                //IGuildUser guildUser = guild.GetUser(Convert.ToUInt64(reaction.UserId));
                //IGuildUser guild = (IGuildUser)client.GetGuild(Convert.ToUInt64(reaction.UserId));// var user = guild.GetUser(Convert.ToUInt64(message));
            }


            return(Task.CompletedTask);
        }
Exemplo n.º 27
0
 private Task Client_MessagesBulkDeleted(IReadOnlyCollection <Cacheable <IMessage, ulong> > arg1, ISocketMessageChannel arg2)
 {
     return(Task.CompletedTask);
 }
Exemplo n.º 28
0
        private async Task HandleMessageEdit(Cacheable <IMessage, ulong> cachedOriginal, SocketMessage updated, ISocketMessageChannel channel)
        {
            //Don't log when Modix edits its own messages
            if (updated.Author.Id == _discordClient.CurrentUser.Id)
            {
                return;
            }

            var guild = (channel as SocketGuildChannel)?.Guild;

            if (guild == null)
            {
                Log.LogInformation("Recieved message update event for non-guild message, ignoring");
                return;
            }

            if (await ShouldSkip(guild, channel))
            {
                return;
            }

            var original = await cachedOriginal.GetOrDownloadAsync();

            //Skip things like embed updates
            if (original.Content == updated.Content)
            {
                return;
            }

            var descriptionText = $"**[Original]({original.GetMessageLink()})**\n```{FormatMessage(original.Content)}```";

            if (descriptionText.Length <= 2048)
            {
                descriptionText += $"\n**Updated**\n```{FormatMessage(updated.Content)}```";;
            }

            var embed = new EmbedBuilder()
                        .WithVerboseAuthor(original.Author)
                        .WithDescription(descriptionText)
                        .WithCurrentTimestamp();

            await SelfExecuteRequest <IDesignatedChannelService>(async designatedChannelService =>
            {
                await designatedChannelService.SendToDesignatedChannelsAsync(
                    guild, DesignatedChannelType.MessageLog,
                    $":pencil:Message Edited in {MentionUtils.MentionChannel(channel.Id)}", embed.Build());
            });
        }
Exemplo n.º 29
0
 private static Task <RestUserMessage> InvalidOption(ISocketMessageChannel channel)
 {
     return(channel.SendMessageAsync("The option you specified doesn't exist. The option should be"
                                     + " just the number of the option you are trying to pick. Try again."));
 }
Exemplo n.º 30
0
        async void CheckForNewLogs()
        {
            List <WowGuildAssociations> guildList    = null;
            List <LogMonitoring>        logWatchList = null;

            try
            {
                using (var db = new NinjaBotEntities())
                {
                    guildList    = db.WowGuildAssociations.ToList();
                    logWatchList = db.LogMonitoring.ToList();
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine($"Error getting guild/logwatch list -> [{ex.Message}]");
            }
            if (guildList != null)
            {
                foreach (var guild in guildList)
                {
                    try
                    {
                        var watchGuild = logWatchList.Where(w => w.ServerId == guild.ServerId).FirstOrDefault();
                        if (watchGuild != null)
                        {
                            if (watchGuild.MonitorLogs)
                            {
                                var logs = await GetReportsFromGuild(guild.WowGuild, guild.WowRealm.Replace("'", ""), guild.WowRegion, isList : true);

                                if (logs != null)
                                {
                                    var      latestLog = logs[0];
                                    DateTime startTime = UnixTimeStampToDateTime(latestLog.start);
                                    if (latestLog.id != watchGuild.ReportId)
                                    {
                                        using (var db = new NinjaBotEntities())
                                        {
                                            var latestForGuild = db.LogMonitoring.Where(l => l.ServerId == guild.ServerId).FirstOrDefault();
                                            latestForGuild.LatestLog = startTime;
                                            latestForGuild.ReportId  = latestLog.id;
                                            await db.SaveChangesAsync();
                                        }
                                        ISocketMessageChannel channel = _client.GetChannel((ulong)watchGuild.ChannelId) as ISocketMessageChannel;
                                        if (channel != null)
                                        {
                                            var embed = new EmbedBuilder();
                                            embed.Title = $"New log found for [{guild.WowGuild}]!";
                                            StringBuilder sb = new StringBuilder();
                                            sb.AppendLine($"[__**{latestLog.title}** **/** **{latestLog.zoneName}**__]({latestLog.reportURL})");
                                            sb.AppendLine($"\t:timer: Start time: **{UnixTimeStampToDateTime(latestLog.start)}**");
                                            //sb.AppendLine($"\tLink: ***");
                                            sb.AppendLine($"\t:mag: [WoWAnalyzer](https://wowanalyzer.com/report/{latestLog.id})");
                                            sb.AppendLine();
                                            embed.Description = sb.ToString();
                                            embed.WithColor(new Color(0, 0, 255));
                                            await channel.SendMessageAsync("", false, embed);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine($"Error checking for logs [{guild.WowGuild}]:[{guild.WowRealm}]:[{guild.WowRealm}]! -> [{ex.Message}]");
                    }
                }
            }
        }