MCPcopy
hub / github.com/smallfawn/QLScriptPublic / bark

Function bark

notify.py:147–188  ·  view source on GitHub ↗

使用 bark 推送消息。

(title: str, content: str)

Source from the content-addressed store, hash-verified

145
146
147def bark(title: str, content: str) -> None:
148 """
149 使用 bark 推送消息。
150 """
151 if not push_config.get("BARK_PUSH"):
152 return
153 print("bark 服务启动")
154
155 if push_config.get("BARK_PUSH").startswith("http"):
156 url = f'{push_config.get("BARK_PUSH")}'
157 else:
158 url = f'https://api.day.app/{push_config.get("BARK_PUSH")}'
159
160 bark_params = {
161 "BARK_ARCHIVE": "isArchive",
162 "BARK_GROUP": "group",
163 "BARK_SOUND": "sound",
164 "BARK_ICON": "icon",
165 "BARK_LEVEL": "level",
166 "BARK_URL": "url",
167 }
168 data = {
169 "title": title,
170 "body": content,
171 }
172 for pair in filter(
173 lambda pairs: pairs[0].startswith("BARK_")
174 and pairs[0] != "BARK_PUSH"
175 and pairs[1]
176 and bark_params.get(pairs[0]),
177 push_config.items(),
178 ):
179 data[bark_params.get(pair[0])] = pair[1]
180 headers = {"Content-Type": "application/json;charset=utf-8"}
181 response = requests.post(
182 url=url, data=json.dumps(data), headers=headers, timeout=15
183 ).json()
184
185 if response["code"] == 200:
186 print("bark 推送成功!")
187 else:
188 print("bark 推送失败!")
189
190
191def console(title: str, content: str) -> None:

Callers

nothing calls this directly

Calls 3

printFunction · 0.70
getMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected