forked from WeakAuras/WeakAuras2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Which includes a curated list of thanks + an automatically updated patreon list.
- Loading branch information
1 parent
7894f9a
commit fa4dd03
Showing
8 changed files
with
344 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
#!/usr/bin/env python3 | ||
import discord | ||
import unicodedata | ||
import os | ||
import sys | ||
|
||
API_TOKEN = os.environ['DISCORD_ACCESS_TOKEN'] | ||
CHANNEL_ID = 1259514390000963594 | ||
MSG_ID = 1260693417336504482 | ||
VALID_ROLES = { | ||
1102916915653001258, # Premium Members | ||
1103105933971836958, # Platinum Support | ||
1103105132239007824, # Gold Support | ||
1102916921004937286, # Silver Support | ||
689250157799407890, # Twitch Subscriber: Tier 3 | ||
689250157799407798, # Twitch Subscriber: Tier 2 | ||
689250157799407691, # Twitch Subscriber: Tier 1 | ||
563427483555201024, # Twitch Subscriber, | ||
507633262445723668, # Patron Bronze | ||
507260546119368714, # Patron Silver | ||
506449385543041034, # Patron Gold | ||
512016261631442945, # Patreon Goldish | ||
635471797583872020, # Patreon Platinum | ||
635471886134018049, # Patreon Diamond | ||
512014685088907265, # Patreon | ||
402021459440173056, # Regular | ||
172440752045948928, # Moderator, | ||
294497613565263872, # Super Moderator | ||
} | ||
|
||
MSG = """React to this message to have your name included in the Thanks list inside the WeakAuras GUI. | ||
The bot runs every monday, and you have to be a member of the discord for the bot to verify your status. | ||
Note, that most symbols are filtered. Pure Latin, Chinese or Korean should be fine. | ||
And the names are reviewed by a human. | ||
The bot is experimental and will probably break a few times. | ||
""" | ||
|
||
file = open("commit-body.txt", "w", encoding="utf-8") | ||
def commitMsgPrint(*text): | ||
string = ' '.join(text) | ||
file.write(string + "\n") | ||
print(string) | ||
|
||
def has_cj(text): | ||
for char in text: | ||
for name in ('CJK','CHINESE','KATAKANA',): | ||
if unicodedata.name(char).startswith(name): | ||
return True | ||
return False | ||
|
||
def has_k(text): | ||
for char in text: | ||
if unicodedata.name(char).startswith("HANGUL"): | ||
return True | ||
return False | ||
|
||
def checkChar(char): | ||
for name in ('CJK','CHINESE','KATAKANA', 'LATIN', 'DIGIT', 'SPACE'): | ||
if unicodedata.name(char).startswith(name): | ||
return True | ||
return False | ||
|
||
def cleanName(name): | ||
newName = "".join([c for c in name if checkChar(c)]).strip() | ||
newName = newName.replace("[=[", "") | ||
newName = newName.replace("]=]", "") | ||
newName = newName.replace("|", "") | ||
newName = newName[:15] | ||
if newName != name: | ||
commitMsgPrint("* Changing \"" + name + "\" to \"" + newName + "\"") | ||
return newName | ||
|
||
|
||
class DiscordNameGather(discord.Client): | ||
mode = "" | ||
messagePerAuthor = {} | ||
|
||
def hasRightRole(self, roles): | ||
for r in roles: | ||
if r.id in VALID_ROLES: | ||
return True | ||
return False | ||
|
||
async def on_ready(self): | ||
for guild in self.guilds: | ||
for channel in guild.channels: | ||
if channel.id == CHANNEL_ID: | ||
if self.mode == "msg": | ||
await self.sendMessage(channel) | ||
elif self.mode == "edit": | ||
await self.editMessage(channel) | ||
elif self.mode == "history": | ||
await self.parseHistory(channel) | ||
else: | ||
await self.parseReactions(channel, MSG_ID) | ||
|
||
await client.close() | ||
|
||
async def sendMessage(self, channel): | ||
message = channel.send(MSG) | ||
commitMsgPrint("Send message with id:", (await message).id) | ||
|
||
async def editMessage(self, channel): | ||
message = await channel.fetch_message(MSG_ID) | ||
await message.edit(content = MSG) | ||
|
||
|
||
# Old method of enumerating messages in a channel | ||
async def parseHistory(self, channel): | ||
messages = [message async for message in channel.history(limit=2000)] | ||
for message in messages: | ||
self.handleHistoryMessage(message) | ||
self.writeFile() | ||
|
||
def handleHistoryMessage(self, message): | ||
if isinstance(message.author, discord.member.Member): | ||
if self.hasRightRole(message.author.roles): | ||
if message.author.id not in self.messagePerAuthor: | ||
self.messagePerAuthor[message.author.id] = message.content | ||
commitMsgPrint(message.author.name, ":", message.content) | ||
else: | ||
commitMsgPrint("Ignoring user, because they don't have the right role:", message.author.name) | ||
|
||
# New method of parsing reactions to a singular message | ||
async def parseReactions(self, channel, msgId): | ||
message = await channel.fetch_message(msgId) | ||
for reaction in message.reactions: | ||
async for user in reaction.users(): | ||
if isinstance(user, discord.member.Member): | ||
if self.hasRightRole(user.roles): | ||
self.messagePerAuthor[user.id] = user.display_name | ||
else: | ||
commitMsgPrint("Ignoring User (missing role): ", user.display_name) | ||
self.writeFile() | ||
|
||
|
||
def writeFile(self): | ||
names = list(self.messagePerAuthor.values()) | ||
|
||
commitMsgPrint("") | ||
commitMsgPrint("Cleaning names") | ||
names = [cleanName(name) for name in names] | ||
names = [name for name in names if name != ""] | ||
|
||
names.sort(key=lambda y: y.lower()) | ||
|
||
cjnames = filter(has_cj, names) | ||
knames = filter(lambda n: not has_cj(n) and has_k(n), names) | ||
latinnames = filter(lambda n: not has_cj(n) and not has_k(n), names) | ||
|
||
file = open("WeakAuras/DiscordList.lua", "w", encoding="utf-8") | ||
file.write("if not WeakAuras.IsLibsOK() then return end\n") | ||
file.write("---@type string\n") | ||
file.write("local AddonName = ...\n") | ||
file.write("---@class Private\n") | ||
file.write("local Private = select(2, ...)\n") | ||
|
||
file.write("Private.PatreonsList = {\n") | ||
commitMsgPrint("") | ||
commitMsgPrint("Final Latin Names List") | ||
for name in latinnames: | ||
file.write(" [=[" + name + "]=],\n") | ||
commitMsgPrint("*", name) | ||
file.write("}\n") | ||
|
||
commitMsgPrint("") | ||
commitMsgPrint("Final China/Japan List") | ||
file.write("Private.PatreonsListCJ = {\n") | ||
for name in cjnames: | ||
file.write(" [=[" + name + "]=],\n") | ||
commitMsgPrint("*", name) | ||
file.write("}\n") | ||
|
||
commitMsgPrint("") | ||
commitMsgPrint("Final Korea List") | ||
file.write("Private.PatreonsListK = {\n") | ||
for name in knames: | ||
file.write(" [=[" + name + "]=],\n") | ||
commitMsgPrint("*", name) | ||
file.write("}\n") | ||
|
||
file.close() | ||
|
||
|
||
intents = discord.Intents.default() | ||
intents.message_content = True | ||
intents.members = True | ||
|
||
client = DiscordNameGather(intents=intents) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) > 1: | ||
client.mode = sys.argv[1] | ||
print("Running in mode", client.mode) | ||
|
||
client.run(API_TOKEN) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Create Discord Name Update Pull Request | ||
|
||
on: | ||
schedule: | ||
- cron: "0 10 * * 1" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
discordUpdate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
- name: Install discord pip | ||
run: | | ||
pip install discord.py | ||
shell: bash | ||
- name: Update Discord list | ||
run: | | ||
/usr/bin/env python3 .github/scripts/discordupdate.py | ||
shell: bash | ||
env: | ||
DISCORD_ACCESS_TOKEN: ${{ secrets.DISCORD_ACCESS_TOKEN}} | ||
|
||
- name: Save Commit Body in Variable | ||
uses: Stanzilla/[email protected] | ||
id: readCommitBody | ||
with: | ||
path: commit-body.txt | ||
|
||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
branch: update-discordlist | ||
commit-message: Update Discord List | ||
title: Update Discord List | ||
body: ${{ steps.readCommitBody.outputs.text }} | ||
delete-branch: true | ||
add-paths: WeakAuras/DiscordList.lua | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
if not WeakAuras.IsLibsOK() then return end | ||
---@type string | ||
local AddonName = ... | ||
---@class Private | ||
local Private = select(2, ...) | ||
Private.PatreonsList = { | ||
|
||
} | ||
Private.PatreonsListCJ = { | ||
|
||
} | ||
Private.PatreonsListK = { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,4 @@ SubRegionTypes\Model.lua | |
|
||
# Misc | ||
Legendaries.lua | ||
DiscordList.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.