コード例 #1
0
ファイル: Functions.cs プロジェクト: anastarawneh/Ja3farBot
 public static async Task Delete(this User user)
 {
     using MySqlConnection connection = MySQL.getConnection();
     string query = $"DELETE FROM Users WHERE ID={user.ID}";
     await connection.ExecuteAsync(query);
 }
コード例 #2
0
ファイル: Functions.cs プロジェクト: anastarawneh/Ja3farBot
 public static async Task SetVerified(this User user, bool verified)
 {
     using MySqlConnection connection = MySQL.getConnection();
     string query = $"UPDATE Users SET EventVerified={verified} WHERE ID={user.ID}";
     await connection.ExecuteAsync(query);
 }
コード例 #3
0
ファイル: Functions.cs プロジェクト: anastarawneh/Ja3farBot
        public static async Task SetSocials(ulong UserID, string site = null, string link = null, SocketCommandContext context = null)
        {
            using MySqlConnection connection = MySQL.getConnection();
            if (connection.State != System.Data.ConnectionState.Open)
            {
                await connection.OpenAsync();
            }
            string query = "";

            if (!socialExists(UserID))
            {
                query = $"INSERT INTO Socials (UserID, Twitter, Instagram, Snapchat, MsgID) " +
                        $"VALUES ({UserID}, 'None', 'None', 'None', 0)";
                await connection.ExecuteAsync(query);
            }

            query = $"SELECT * FROM Socials WHERE UserID={UserID}";
            Social current = await connection.QueryFirstAsync <Social>(query);

            switch (site.ToLower())
            {
            case "twitter":
                current.Twitter = link;
                break;

            case "instagram":
                current.Instagram = link;
                break;

            case "snapchat":
                current.Snapchat = link;
                break;

            default:
                Exception ex = new Exception(message: ":x: Please specify a vaild site. Available sites are (Twitter/Instagram/Snapchat).");
                throw ex;
            }

            query = $"UPDATE Socials SET Twitter='{current.Twitter}', Instagram='{current.Instagram}', " +
                    $"Snapchat='{current.Snapchat}' WHERE UserID={UserID}";
            await connection.ExecuteAsync(query);

            EmbedBuilder embed = new EmbedBuilder();

            embed.WithAuthor(context.User.ToString(), context.User.GetAvatarUrl());
            embed.WithColor(114, 137, 218);
            if (GetSocial(UserID, "twitter") == null || GetSocial(UserID, "twitter") == "None")
            {
                embed.AddField("Twitter", "None");
            }
            else if (GetSocial(UserID, "twitter") == "None")
            {
                embed.AddField("Twitter", $"[{GetSocial(UserID, "twitter")}](https://twitter.com/" + GetSocial(UserID, "twitter") + ")");
            }
            else
            {
                embed.AddField("Twitter", $"[@{GetSocial(UserID, "twitter")}](https://twitter.com/" + GetSocial(UserID, "twitter") + ")");
            }
            if (GetSocial(UserID, "instagram") == null || GetSocial(UserID, "instagram") == "None")
            {
                embed.AddField("Instagram", "None");
            }
            else if (GetSocial(UserID, "instagram") == "None")
            {
                embed.AddField("Instagram", $"[{GetSocial(UserID, "instagram")}](https://instagram.com/" + GetSocial(UserID, "instagram") + ")");
            }
            else
            {
                embed.AddField("Instagram", $"[@{GetSocial(UserID, "instagram")}](https://instagram.com/" + GetSocial(UserID, "instagram") + ")");
            }
            if (GetSocial(UserID, "snapchat") == null)
            {
                embed.AddField("Snapchat", "None");
            }
            else
            {
                embed.AddField("Snapchat", $"{GetSocial(UserID, "snapchat")}");
            }

            ulong                  chnlid     = Data.GetChnlId("socials");;
            SocketTextChannel      socialchnl = Constants.IGuilds.Jordan(context).Channels.Where(x => x.Id == chnlid).FirstOrDefault() as SocketTextChannel;
            IEnumerable <IMessage> msgs       = await socialchnl.GetMessagesAsync(100).FlattenAsync();

            foreach (IMessage msg in msgs)
            {
                if (msg.Id == GetMsgId(context.User.Id))
                {
                    await(msg as IUserMessage).ModifyAsync(x => x.Embed = embed.Build());
                    return;
                }
            }

            RestUserMessage msg_ = await socialchnl.SendMessageAsync("", false, embed.Build());

            query = $"UPDATE Socials SET MsgID={msg_.Id} WHERE UserID={UserID}";
            await connection.ExecuteAsync(query);
        }