1 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
2 # Copyright (C) 2023 Free Software Foundation
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from fba.helpers import tidyup
21 logging.basicConfig(level=logging.INFO)
22 logger = logging.getLogger(__name__)
24 # A list of relay software
34 # Cache for function alias()
38 def alias(software: str) -> str:
39 logger.debug("software='%s'- CALLED!", software)
41 if not isinstance(software, str) and software is not None:
42 raise ValueError(f"software[]='{type(software)}' is not type 'str'")
44 raise ValueError("Parameter 'software' is empty")
45 elif software in _cache["alias"]:
46 logger.debug("Returning cached alias='%s' - EXIT!", _cache["alias"][software])
47 return _cache["alias"][software]
51 logger.debug("software='%s'- BEFORE!", software)
52 software = tidyup.domain(software)
53 logger.debug("software='%s'- AFTER!", software)
55 if software in ["akkoma", "rebased", "akkounfucked", "ched", "incestoma", "revolver"]:
56 logger.debug("Setting pleroma: software='%s'", software)
58 elif "radiant" in software:
59 logger.debug("Setting radiant: software='%s'", software)
61 elif software in ["hometown", "ecko", "fedibird", "glitchcafe"] or "되는 마스토돈" in software or "mastodon" in software:
62 logger.debug("Setting mastodon: software='%s'", software)
64 elif software in ["slipfox calckey", "calckey", "groundpolis", "foundkey", "cherrypick", "meisskey", "magnetar", "keybump", "dolphin", "calckey social", "azk.sns", "firefish", "qtmmsky", "iceshrimp", "owohub", "re+", "russkey", "loverskey", "hajkey", "sharkey", "renekey", "renekey-lite", "yoiyami", "catnip", "cyberskey", "catodon", "lycheebridge"] or "shumihub" in software or "мисскей" in software or "milkey" in software or "misskey" in software:
65 logger.debug("Setting misskey: software='%s'", software)
67 elif software in ["runtube.re", "islameye"]:
68 logger.debug("Setting peertube: software='%s'", software)
70 elif software in ["nextcloud social", "nextcloudpi", "storage share", "nube"] or "nextcloud" in software:
71 logger.debug("Setting nextcloud: software='%s'", software)
72 software = "nextcloud"
73 elif "discourse" in software:
74 logger.debug("Setting discourse: software='%s'", software)
75 software = "discourse"
76 elif software == "activity-relay":
77 logger.debug("Setting activityrelay: software='%s'", software)
78 software = "activityrelay"
79 elif "owncast" in software:
80 logger.debug("Setting owncast: software='%s'", software)
82 elif software in ["streams-hubzilla-social", "streams13"]:
83 logger.debug("Setting streams: software='%s'", software)
85 elif software == "roadhouse":
86 logger.debug("Setting hubzilla: software='%s'", software)
88 elif software == "takahē":
89 logger.debug("Setting takahe: software='%s'", software)
91 elif software == "diaspora* social network":
92 logger.debug("Setting diaspora: software='%s'", software)
94 elif software == "tkz relay":
95 logger.debug("Setting aoderelay: software='%s'", software)
96 software = "aoderelay"
97 elif software == "gitdab":
98 logger.debug("Setting forgejo: software='%s'", software)
100 elif software == "mbin":
101 logger.debug("Setting kbin: software='%s'", software)
103 elif software == "write.as":
104 logger.debug("Setting writefreely: software='%s'", software)
105 software = "writefreely"
106 elif "gnu social" in software:
107 logger.debug("Setting gnusocial: software='%s'", software)
108 software = "gnusocial"
109 elif software.find("/") > 0:
110 logger.warning("Spliting of slash: software='%s'", software)
111 software = software.split("/")[-1]
112 elif software.find("|") > 0:
113 logger.warning("Spliting of pipe: software='%s'", software)
114 software = software.split("|")[0]
115 elif "powered by" in software:
116 logger.debug("software='%s' has 'powered by' in it", software)
117 software = strip_powered_by(software)
118 elif software.endswith(" experimental"):
119 logger.debug("software='%s' ends with 'experimental", software)
120 software = strip_until(software, "experimental")
122 if isinstance(software, str) and " by " in software:
123 logger.debug("software='%s' has ' by ' in it", software)
124 software = strip_until(software, " by ")
125 elif isinstance(software, str) and " - " in software:
126 logger.debug("software='%s' has ' - ' in it", software)
127 software = strip_until(software, " - ")
128 elif isinstance(software, str) and " see " in software:
129 logger.debug("software='%s' has ' see ' in it", software)
130 software = strip_until(software, " see ")
132 logger.debug("software['%s']='%s'", type(software), software)
134 logger.warning("tidyup.domain() left no software name behind: software='%s'", software)
137 logger.debug("software='%s' is being cleaned up further ...")
138 software = software.rstrip("!").strip()
141 _cache["alias"][key] = software
143 logger.debug("software[%s]='%s' - EXIT!", type(software), software)
146 def strip_hosted_on(software: str) -> str:
147 logger.debug("software='%s' - CALLED!", software)
149 if not isinstance(software, str):
150 raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'")
152 raise ValueError("Parameter 'software' is empty")
153 elif "hosted on" not in software:
154 logger.warning("Cannot find 'hosted on' in software='%s'!", software)
157 end = software.find("hosted on ")
158 logger.debug("end[%s]=%d", type(end), end)
160 software = software[0:end].strip()
161 logger.debug("software[%s]='%s'", type(software), software)
163 if " - " in software:
164 logger.debug("Stripping ' - ' of from software='%s' ...", software)
165 software = strip_until(software, " - ").strip()
167 logger.debug("software='%s' - EXIT!", software)
170 def strip_powered_by(software: str) -> str:
171 logger.debug("software='%s' - CALLED!", software)
173 if not isinstance(software, str):
174 raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'")
176 raise ValueError("Parameter 'software' is empty")
177 elif "powered by" not in software:
178 logger.warning("Cannot find 'powered by' in software='%s'!", software)
181 start = software.find("powered by ")
182 logger.debug("start[%s]=%d", type(start), start)
184 software = software[start + 11:].strip()
185 logger.debug("software='%s'", software)
187 if " - " in software:
188 logger.debug("Stripping ' - ' of from software='%s' ...", software)
189 software = strip_until(software, " - ").strip()
191 logger.debug("software='%s' - EXIT!", software)
194 def strip_until(software: str, until: str) -> str:
195 logger.debug("software='%s',until='%s' - CALLED!", software, until)
197 if not isinstance(software, str):
198 raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'")
200 raise ValueError("Parameter 'software' is empty")
201 elif not isinstance(until, str):
202 raise ValueError(f"Parameter until[]='{type(until)}' is not of type 'str'")
204 raise ValueError("Parameter 'until' is empty")
205 elif not until in software:
206 logger.warning("Cannot find until='%s' in software='%s'!", until, software)
209 # Next, strip until part
210 end = software.strip().find(until)
212 logger.debug("end[%s]=%d", type(end), end)
214 software = software[0:end].strip()
216 logger.debug("software='%s' - EXIT!", software)
219 def is_relay(software: str) -> bool:
220 logger.debug("software='%s'- CALLED!", software)
222 if not isinstance(software, str):
223 raise ValueError(f"software[]='{type(software)}' is not type 'str'")
225 raise ValueError("Parameter 'software' is empty")
227 found = software in relays
229 logger.debug("found='%s' - EXIT!", found)