Esempio n. 1
0
 public async Task postMessage(ulong channelid, string message)
 {
     if (message.Length > 2000)
     {
         Log("Message lenght limit hit " + message.Length + "\n" + message, LogType.Crash);
         return;
     }
     try
     {
         IMessageChannel chnl = main._client.GetChannel(channelid) as IMessageChannel;
         //Guildname = ((SocketGuildChannel)chnl).Guild.Name;
         if (chnl != null)
         {
             SocketGuildChannel gchnl = (SocketGuildChannel)chnl;
             await chnl.SendMessageAsync(message);
         }
         else
         {
             Compfort.Log("Channel not found: " + channelid);
         }
     }
     catch (Discord.Net.HttpException ex)
     {
         if (ex.DiscordCode == null || (ex.DiscordCode != 50013 && ex.DiscordCode != 50001))
         {
             Compfort.Log("Exception for channel: " + channelid + " - " + ex.Message);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Gets all tribes from a server
        /// </summary>
        /// <param name="guildid"></param>
        /// <param name="sData"></param>
        /// <returns></returns>
        public static List <TribeData> GetTribes(ulong guildid, ServerData sData)
        {
            List <TribeData> rg = new List <TribeData>();

            if (Directory.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\Tribes\\"))
            {
                string[] tribes = Directory.GetDirectories(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\Tribes\\");
                foreach (string s in tribes)
                {
                    if (File.Exists(s + "\\servers.txt"))
                    {
                        bool found = false;
                        foreach (string server in File.ReadAllText(s + "\\servers.txt").Split('\n'))
                        {
                            if (server.CompareTo(sData.Name) == 0)
                            {
                                found = true;
                            }
                        }
                        if (found)
                        {
                            rg.Add(new TribeData()
                            {
                                GuildID  = guildid,
                                ID       = int.Parse(s.Split("\\/".ToCharArray())[s.Split("\\/".ToCharArray()).Length - 1]),
                                name     = File.ReadAllText(s + "\\name.txt"),
                                relation = Compfort.IntToRelationship(int.Parse(File.ReadAllText(s + "\\relation.txt")))
                            });
                        }
                    }
                }
            }
            return(rg);
        }
Esempio n. 3
0
 /// <summary>
 /// Gets the relationship of a tribe
 /// </summary>
 /// <param name="guildid"></param>
 /// <param name="tribeID"></param>
 /// <returns></returns>
 public static Relationship GetRelationship(ulong guildid, int tribeID)
 {
     if (Directory.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\Tribes\\" + tribeID))
     {
         return(Compfort.IntToRelationship(int.Parse(File.ReadAllText(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\Tribes\\" + tribeID + "\\relation.txt"))));
     }
     return(Relationship.unknown);
 }
Esempio n. 4
0
        /// <summary>
        /// Returns all tribes in a guild(discord server)
        /// </summary>
        /// <param name="guildid"></param>
        /// <returns></returns>
        public static List <TribeData> GetTribes(ulong guildid)
        {
            List <TribeData> rg = new List <TribeData>();

            if (Directory.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\Tribes\\"))
            {
                string[] tribes = Directory.GetDirectories(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\Tribes\\");
                foreach (string s in tribes)
                {
                    rg.Add(new TribeData()
                    {
                        GuildID  = guildid,
                        ID       = int.Parse(s.Split("\\/".ToCharArray())[s.Split("\\/".ToCharArray()).Length - 1]),
                        name     = File.ReadAllText(s + "\\name.txt"),
                        relation = Compfort.IntToRelationship(int.Parse(File.ReadAllText(s + "\\relation.txt")))
                    });
                }
            }
            return(rg);
        }
Esempio n. 5
0
 public async Task postMessages(ulong channelid, List <String> messages)
 {
     try
     {
         IMessageChannel chnl = main._client.GetChannel(channelid) as IMessageChannel;
         if (chnl != null)
         {
             SocketGuildChannel gchnl = (SocketGuildChannel)chnl;
             foreach (String message in messages)
             {
                 await chnl.SendMessageAsync(message);
             }
         }
         else
         {
             Compfort.Log("Channel not found: " + channelid);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Returns the data for a certain steamid
        /// </summary>
        /// <param name="guilid"></param>
        /// <returns></returns>
        public static SteamIDData GetSteamID(ulong guildid, ulong steamid)
        {
            SteamIDData rg = new SteamIDData {
                SteamID = steamid
            };

            if (Directory.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\SteamIDs\\" + steamid))
            {
                if (File.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\SteamIDs\\" + steamid + "\\Name.txt"))
                {
                    rg.name = File.ReadAllText(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\SteamIDs\\" + steamid + "\\Name.txt");
                }
                if (File.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\SteamIDs\\" + steamid + "\\Relationship.txt"))
                {
                    rg.relation = Compfort.IntToRelationship(int.Parse(File.ReadAllText(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\SteamIDs\\" + steamid + "\\Relationship.txt")));
                }
                if (File.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\SteamIDs\\" + steamid + "\\Tribe.txt"))
                {
                    rg.tribe = Compfort.GetTribeByID(guildid, int.Parse(File.ReadAllText(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\SteamIDs\\" + steamid + "\\Tribe.txt")));
                }
            }
            return(rg);
        }
Esempio n. 7
0
        public async Task postMessageTask()
        {
            Compfort.Log("Started PostMessageTask");
            await Task.Delay(1);

            try
            {
                while (true)
                {
                    if (current != null)
                    {
                        if (current.next != null)
                        {
                            current = current.next;
                            await postMessage(current.channelid, current.Message);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Compfort.Log("PostMessageTask crashed", LogType.Crash);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Returns all alerts created for a server
        /// </summary>
        /// <param name="sData"></param>
        /// <returns></returns>
        public static List <AlertData> GetAlerts(ServerData sData)
        {
            List <AlertData> rg = new List <AlertData>();

            if (Directory.Exists(AppContext.BaseDirectory + "\\Guilds\\"))
            {
                foreach (string guilddir in Directory.GetDirectories(AppContext.BaseDirectory + "\\Guilds\\"))
                {
                    if (File.Exists(guilddir + "\\alerts.txt"))
                    {
                        ulong guildid = ulong.Parse(guilddir.Split("\\/".ToCharArray())[guilddir.Split("\\/".ToCharArray()).Length - 1]);
                        foreach (string alert in File.ReadAllLines(guilddir + "\\alerts.txt"))
                        {
                            if (sData.Name.CompareTo(alert.Split(';')[0]) == 0)
                            {
                                rg.Add(new AlertData(guildid, ulong.Parse(alert.Split(';')[2]), Compfort.IntToRelationship(int.Parse(alert.Split(';')[1])), alert.Split(';')[3]));
                            }
                        }
                    }
                }
            }
            return(rg);
        }
Esempio n. 9
0
 /// <summary>
 /// Deletes an alert, the alert is already getting removed out of the cache at an other location
 /// </summary>
 /// <param name="guildid"></param>
 /// <param name="relation"></param>
 /// <param name="sData"></param>
 public static void DeleteAlert(ulong guildid, ulong channelid, Relationship relation, ServerData sData)
 {
     if (!Directory.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\"))
     {
         Directory.CreateDirectory(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\");
     }
     if (File.Exists(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\alerts.txt"))
     {
         string[] alerts  = File.ReadAllLines(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\alerts.txt");
         string   newfile = "";
         foreach (string alert in alerts)
         {
             if (ulong.Parse(alert.Split(':')[2]) != channelid && relation.CompareTo(Compfort.IntToRelationship(int.Parse(alert.Split(':')[1]))) == 0)
             {
                 if (newfile != "")
                 {
                     newfile += ",";
                 }
                 newfile += alert;
             }
         }
         if (newfile.Length > 0)
         {
             File.WriteAllText(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\alerts.txt", newfile);
         }
         else
         {
             File.Delete(AppContext.BaseDirectory + "\\Guilds\\" + guildid + "\\alerts.txt");
         }
     }
 }