Merge pull request 'Now filters emojo by tag and adds more blanks' (#2) from feature-emoji-file into main

Reviewed-on: #2
This commit is contained in:
bombinans 2025-11-02 00:12:09 +00:00
commit 71dad6e25f
3 changed files with 79 additions and 43 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# grawlix
A bot for posting grids of emojis to GoToSocial or Mastodon

View File

@ -1,4 +1,4 @@
:grawlix_null: blank :grawlix_null: mono blank
:grawlix_angle: colour yellow :grawlix_angle: colour yellow
:grawlix_ball1: colour green :grawlix_ball1: colour green
:grawlix_ball2: colour blue :grawlix_ball2: colour blue
@ -6,51 +6,51 @@
:grawlix_bullseye: colour :grawlix_bullseye: colour
:grawlix_bun: colour yellow :grawlix_bun: colour yellow
:grawlix_claw: colour red :grawlix_claw: colour red
:grawlix_cloud: :grawlix_cloud: mono
:grawlix_crosses: texture :grawlix_crosses: mono texture
:grawlix_crumple: texture :grawlix_crumple: mono texture
:grawlix_drop: colour purple :grawlix_drop: colour purple
:grawlix_dust1: texture :grawlix_dust1: mono texture
:grawlix_dust2: texture :grawlix_dust2: mono texture
:grawlix_feather: colour green :grawlix_feather: colour green
:grawlix_flower: colour blue :grawlix_flower: colour blue
:grawlix_fruit: colour green :grawlix_fruit: colour green
:grawlix_fungus: colour yellow :grawlix_fungus: colour yellow
:grawlix_fur: texture :grawlix_fur: mono texture
:grawlix_gadget: colour red :grawlix_gadget: colour red
:grawlix_globule: colour pink :grawlix_globule: colour pink
:grawlix_glyph1: glyph :grawlix_glyph1: mono glyph
:grawlix_glyph10: glyph :grawlix_glyph10: mono glyph
:grawlix_glyph2: glyph :grawlix_glyph2: mono glyph
:grawlix_glyph3: glyph :grawlix_glyph3: mono glyph
:grawlix_glyph4: glyph :grawlix_glyph4: mono glyph
:grawlix_glyph5: glyph :grawlix_glyph5: mono glyph
:grawlix_glyph6: glyph :grawlix_glyph6: mono glyph
:grawlix_glyph7: glyph :grawlix_glyph7: mono glyph
:grawlix_glyph8: glyph :grawlix_glyph8: mono glyph
:grawlix_glyph9: glyph :grawlix_glyph9: mono glyph
:grawlix_growth: :grawlix_growth: mono
:grawlix_hatch: texture :grawlix_hatch: mono texture
:grawlix_helm: colour red :grawlix_helm: colour red
:grawlix_horizon: colour pink :grawlix_horizon: colour pink
:grawlix_joint: texture :grawlix_joint: mono texture
:grawlix_knothole: texture :grawlix_knothole: mono texture
:grawlix_link: colour trans :grawlix_link: colour trans
:grawlix_lump: colour yellow :grawlix_lump: colour yellow
:grawlix_mountain: colour blue :grawlix_mountain: colour blue
:grawlix_orbit: :grawlix_orbit: mono
:grawlix_popup: colour yellow :grawlix_popup: colour yellow
:grawlix_rects: colour trans :grawlix_rects: colour trans
:grawlix_rough: colour texture pink :grawlix_rough: colour texture pink
:grawlix_scales: colour texture red :grawlix_scales: colour texture red
:grawlix_scrawl: texture :grawlix_scrawl: mono texture
:grawlix_scribble: colour texture green :grawlix_scribble: colour texture green
:grawlix_shatter: colour texture :grawlix_shatter: colour texture
:grawlix_signal: colour :grawlix_signal: colour
:grawlix_slump: colour texture green :grawlix_slump: colour texture green
:grawlix_spark1: :grawlix_spark1: mono
:grawlix_spark2: :grawlix_spark2: mono
:grawlix_sprout: :grawlix_sprout: mono
:grawlix_strata: texture :grawlix_strata: mono texture
:grawlix_vertical: texture :grawlix_vertical: mono texture
:grawlix_wreck: texture colour blue :grawlix_wreck: texture colour blue

View File

@ -1,25 +1,55 @@
import random import random
import sys import sys
from botclient.botclient import Bot from botclient.botclient import Bot
from collections import defaultdict
GRAWLIX = [
"angle", "ball1", "ball2", "brick", "bullseye", "bun", "claw", "cloud",
"crosses", "crumple", "drop", "dust1", "dust2", "feather", "flower", "fruit",
"fungus", "fur", "gadget", "globule", "glyph1", "glyph10", "glyph2", "glyph3",
"glyph4", "glyph5", "glyph6", "glyph7", "glyph8", "glyph9", "growth", "hatch",
"helm", "horizon", "joint", "knothole", "link", "lump", "mountain", "null",
"orbit", "popup", "rects", "rough", "scales", "scrawl", "scribble", "shatter",
"signal", "slump", "spark1", "spark2", "sprout", "strata", "vertical", "wreck",
]
GRID_TYPES = [ "latin_square", "concentric", "sator", "random", "vertical", "horizontal" ] GRID_TYPES = [ "latin_square", "concentric", "sator", "random", "vertical", "horizontal" ]
BLANK_P = {
0: 3,
1: 2,
2: 2,
3: 1,
4: 1,
5: 1,
6: 0,
7: 0,
8: 0,
9: 0,
}
class Grawlix(Bot): class Grawlix(Bot):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.ap.add_argument('-a', '--all', action='store_true', help="Dump a random grid of emojos") self.ap.add_argument('-a', '--all', action='store_true', help="Dump a random grid of emojos")
self.ap.add_argument('-t', '--test', action='store_true', help="Dump emojo list")
def load_emojos(self):
self.emojos = []
self.groups = defaultdict(set)
with open(self.cf["emojos"], "r") as efh:
for line in efh:
parts = line.split()
self.emojos.append(parts[0])
for tag in parts[1:]:
self.groups[tag].add(parts[0])
self.tags = [ t for t in self.groups.keys() if not t == "blank" ]
def make_glyphset(self, n):
blanks_r = random.randrange(10)
blanks_n = BLANK_P[blanks_r]
emojos_n = n - blanks_n
if "groups" in self.cf and random.randrange(2) == 0:
tag = random.choice(self.cf["groups"])
glyphset = random.sample(list(self.groups[tag]), emojos_n)
else:
glyphset = random.sample(self.emojos, emojos_n)
blank = list(self.groups["blank"])[0]
glyphset += ( [ blank ] * blanks_n )
random.shuffle(glyphset)
return glyphset
def latin_square(self): def latin_square(self):
return [ return [
@ -82,10 +112,6 @@ class Grawlix(Bot):
def grid_glyphs(self, grid): def grid_glyphs(self, grid):
return max([max(row) for row in grid]) + 1 return max([max(row) for row in grid]) + 1
def make_glyphset(self, n):
names = random.sample(GRAWLIX, n)
return [ f":grawlix_{name}:" for name in names ]
def render_row(self, row, glyphs): def render_row(self, row, glyphs):
return " ".join([glyphs[c] for c in row]) return " ".join([glyphs[c] for c in row])
@ -93,12 +119,14 @@ class Grawlix(Bot):
grid = self.make_grid() grid = self.make_grid()
n = self.grid_glyphs(grid) n = self.grid_glyphs(grid)
glyphs = self.make_glyphset(n) glyphs = self.make_glyphset(n)
if self.args.dry_run:
print(glyphs)
rows = [ self.render_row(r, glyphs) for r in grid ] rows = [ self.render_row(r, glyphs) for r in grid ]
return "\n".join(rows) return "\n".join(rows)
def header(self): def header(self):
for r in range(20): for r in range(20):
names = [ random.choice(GRAWLIX) for c in range(100) ] names = [ random.choice(self.emojos) for c in range(100) ]
files = [ f'<img src="grawlix_{n}.png" />&nbsp;' for n in names ] files = [ f'<img src="grawlix_{n}.png" />&nbsp;' for n in names ]
print(''.join(files)) print(''.join(files))
print('<br />') print('<br />')
@ -108,9 +136,14 @@ class Grawlix(Bot):
if __name__ == '__main__': if __name__ == '__main__':
g = Grawlix() g = Grawlix()
g.configure() g.configure()
g.load_emojos()
if g.args.all: if g.args.all:
g.header() g.header()
sys.exit(1) sys.exit(1)
if g.args.test:
print(g.tags)
print(g.cf)
sys.exit(1)
post = g.render() post = g.render()
g.wait() g.wait()
g.post(post) g.post(post)