From 6df9c2dedd977401909a1ebfb83471b3d0ad3b86 Mon Sep 17 00:00:00 2001 From: Denevien Date: Sun, 1 Dec 2013 22:16:12 -0600 Subject: [PATCH 1/5] Added search plugin Uses .search SEARCHTYPE INPUT Searchtypes: "name" and "id". Inputs: "name" - 1 word keyword: uses the block name to return a list of block names that contain the keyword and the id for that block. "id" - can be "###" or "###:###": uses the block ID to return the block name. --- ZomgBot/plugins/search | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 ZomgBot/plugins/search diff --git a/ZomgBot/plugins/search b/ZomgBot/plugins/search new file mode 100644 index 0000000..969709e --- /dev/null +++ b/ZomgBot/plugins/search @@ -0,0 +1,77 @@ +from ZomgBot.plugins import Plugin, Modifier + + +@Plugin.register(depends=["commands"]) +class Search(Plugin): + + @Modifier.command("search") + def cmd_search(self, context): + if context.args[0:] == None: + return 'Use ".search SEARCH_TYPE INPUT". Possible search types are "name" and "id". When using "name", insert a one word keyword from a block type name to get a list of matching results. When using "id", enter a block id # to find the block name.' + inputs = context.args[0:] + inputs = inputs.split + if len(inputs) == 1: + if inputs == 'name': + return 'Use ".search name INPUT". The input should be a one word keyword from the block name. This will return a list of matching results.' + if inputs == 'id': + return 'Use ".search id INPUT". The input should be an item id, and will return any match(es)' + if len(inputs) > 2: + return 'Invalid syntax. Use ".search SEARCH_TYPE INPUT". Possible search types are "name" and "id". When using "name", insert a one word keyword from a block type name to get a list of matching results. When using "id", enter a block id # to find the block name.' + else: + return search(inputs[0],inputs[1]) + + + def search(search_type, term): + items_list = [] + with open('items.txt') as inputfile: + for line in inputfile: + items_list.append(line.split()) + results = '' + if search_type == 'name': + for set in items_list: + length = len(set) + for x in range(1,length): + word = set[x] + if word[0] == '(': + if word[-1] == ')': + word = word[1:-1] + else: + word = word[1:] + if word[-1] == ')': + word = word[:-1] + word = word.lower() + term = term.lower() + if word == term: + current = '' + if results != '': + current += ', ' + current += set[0] + ' - ' + set[1] + if length > 2: + for x in range(2, length): + current += ' ' + set[x] + results += current + return results + if search_type == 'id': + for set in items_list: + entry = set[0] + if term.find(':') != -1: + if term == entry: + results += set[0] + ': ' + set[1] + if length > 2: + for x in range(2, length): + results += set[x] + return results + else: + if entry.find(':') != -1: + stop = entry.find(':') + id_num = entry[:stop] + if term == id_num: + current = '' + if results != '': + current += ', ' + current += set[0] + ': ' + set[1] + if length > 2: + for x in range(2, length): + current += set[x] + results += current + return results From 5f4a0b4226f2566d2e63228f238a37ce9106e8ce Mon Sep 17 00:00:00 2001 From: Denevien Date: Sun, 1 Dec 2013 22:16:49 -0600 Subject: [PATCH 2/5] Edited filename to have extension --- ZomgBot/plugins/{search => search.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ZomgBot/plugins/{search => search.py} (100%) diff --git a/ZomgBot/plugins/search b/ZomgBot/plugins/search.py similarity index 100% rename from ZomgBot/plugins/search rename to ZomgBot/plugins/search.py From 88c891045004c9a1e7ee0c630d66551f739dc1e9 Mon Sep 17 00:00:00 2001 From: Denevien Date: Sun, 1 Dec 2013 22:18:23 -0600 Subject: [PATCH 3/5] Created .txt file containing all block names and ids to be used by search.py --- ZomgBot/plugins/items.txt | 610 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 610 insertions(+) create mode 100644 ZomgBot/plugins/items.txt diff --git a/ZomgBot/plugins/items.txt b/ZomgBot/plugins/items.txt new file mode 100644 index 0000000..bf62228 --- /dev/null +++ b/ZomgBot/plugins/items.txt @@ -0,0 +1,610 @@ +1 Stone +2 Grass +3 Dirt +3:2 Podzol +4 Cobblestone +5 Wooden Plank (Oak) +5:1 Wooden Plank (Spruce) +5:2 Wooden Plank (Birch) +5:3 Wooden Plank (Jungle) +6 Sapling (Oak) +6:1 Sapling (Spruce) +6:2 Sapling (Birch) +6:3 Sapling (Jungle) +6:4 Sapling (Acacia) +6:5 Sapling (Dark Oak) +7 Bedrock +8 Water +9 Water (No Spread) +10 Lava +11 Lava (No Spread) +12 Sand +12:1 Red Sand +13 Gravel +14 Gold Ore +15 Iron Ore +16 Coal Ore +17 Wood (Oak) +17:1 Wood (Spruce) +17:2 Wood (Birch) +17:3 Wood (Jungle) +17:4 Wood (Oak 4) +17:5 Wood (Oak 5) +18 Leaves (Oak) +18:1 Leaves (Spruce) +18:2 Leaves (Birch) +18:3 Leaves (Jungle) +19 Sponge +20 Glass +21 Lapis Lazuli Ore +22 Lapis Lazuli Block +23 Dispenser +24 Sandstone +24:1 Sandstone (Chiseled) +24:2 Sandstone (Smooth) +25 Note Block +26 Bed (Block) +27 Rail (Powered) +28 Rail (Detector) +29 Sticky Piston +30 Cobweb +31 Tall Grass (Dead Shrub) +31:1 Tall Grass +31:2 Tall Grass (Fern) +32 Dead Shrub +33 Piston +34 Piston (Head) +35 Wool +35:1 Orange Wool +35:2 Magenta Wool +35:3 Light Blue Wool +35:4 Yellow Wool +35:5 Lime Wool +35:6 Pink Wool +35:7 Gray Wool +35:8 Light Gray Wool +35:9 Cyan Wool +35:10 Purple Wool +35:11 Blue Wool +35:12 Brown Wool +35:13 Green Wool +35:14 Red Wool +35:15 Black Wool +36 Piston (Moving) +37 Dandelion +38 Poppy +38:1 Blue Orchid +38:2 Allium +38:4 Red Tulip +38:5 Orange Tulip +38:6 White Tulip +38:7 Pink Tulip +38:8 Oxeye Daisy +39 Brown Mushroom +40 Red Mushroom +41 Block of Gold +42 Block of Iron +43 Stone Slab (Double) +43:1 Sandstone Slab (Double) +43:2 Wooden Slab (Double) +43:3 Cobblestone Slab (Double) +43:4 Brick Slab (Double) +43:5 Stone Brick Slab (Double) +43:6 Nether Brick Slab (Double) +43:7 Quartz Slab (Double) +43:8 Smooth Stone Slab (Double) +43:9 Smooth Sandstone Slab (Double) +44 Stone Slab +44:1 Sandstone Slab +44:2 Wooden Slab +44:3 Cobblestone Slab +44:4 Brick Slab +44:5 Stone Brick Slab +44:6 Nether Brick Slab +44:7 Quartz Slab +45 Brick +46 TNT +47 Bookshelf +48 Moss Stone +49 Obsidian +50 Torch +51 Fire +52 Mob Spawner +53 Wooden Stairs (Oak) +54 Chest +55 Redstone Wire +56 Diamond Ore +57 Block of Diamond +58 Workbench +59 Wheat (Crop) +60 Farmland +61 Furnace +62 Furnace (Smelting) +63 Sign (Block) +64 Wood Door (Block) +65 Ladder +66 Rail +67 Cobblestone Stairs +68 Sign (Wall Block) +69 Lever +70 Stone Pressure Plate +71 Iron Door (Block) +72 Wooden Pressure Plate +73 Redstone Ore +74 Redstone Ore (Glowing) +75 Redstone Torch (Off) +76 Redstone Torch +77 Button (Stone) +78 Snow +79 Ice +80 Snow Block +81 Cactus +82 Clay Block +83 Sugar Cane (Block) +84 Jukebox +85 Fence +86 Pumpkin +87 Netherrack +88 Soul Sand +89 Glowstone +90 Portal +91 Jack-O-Lantern +92 Cake (Block) +93 Redstone Repeater (Block Off) +94 Redstone Repeater (Block On) +95 Stained Glass (White) +95:1 Stained Glass (Orange) +95:2 Stained Glass (Magenta) +95:3 Stained Glass (Light Blue) +95:4 Stained Glass (Yellow) +95:5 Stained Glass (Lime) +95:6 Stained Glass (Pink) +95:7 Stained Glass (Gray) +95:8 Stained Glass (Light Grey) +95:9 Stained Glass (Cyan) +95:10 Stained Glass (Purple) +95:11 Stained Glass (Blue) +95:12 Stained Glass (Brown) +95:13 Stained Glass (Green) +95:14 Stained Glass (Red) +95:15 Stained Glass (Black) +96 Trapdoor +97 Monster Egg (Stone) +97:1 Monster Egg (Cobblestone) +97:2 Monster Egg (Stone Brick) +97:3 Monster Egg (Mossy Stone Brick) +97:4 Monster Egg (Cracked Stone) +97:5 Monster Egg (Chiseled Stone) +98 Stone Bricks +98:1 Mossy Stone Bricks +98:2 Cracked Stone Bricks +98:3 Chiseled Stone Brick +99 Brown Mushroom (Block) +100 Red Mushroom (Block) +101 Iron Bars +102 Glass Pane +103 Melon (Block) +104 Pumpkin Vine +105 Melon Vine +106 Vines +107 Fence Gate +108 Brick Stairs +109 Stone Brick Stairs +110 Mycelium +111 Lily Pad +112 Nether Brick +113 Nether Brick Fence +114 Nether Brick Stairs +115 Nether Wart +116 Enchantment Table +117 Brewing Stand (Block) +118 Cauldron (Block) +119 End Portal +120 End Portal Frame +121 End Stone +122 Dragon Egg +123 Redstone Lamp +124 Redstone Lamp (On) +125 Oak-Wood Slab (Double) +125:1 Spruce-Wood Slab (Double) +125:2 Birch-Wood Slab (Double) +125:3 Jungle-Wood Slab (Double) +125:4 Acacia Wood Slab (Double) +125:5 Dark Oak Wood Slab (Double) +126 Oak-Wood Slab +126:1 Spruce-Wood Slab +126:2 Birch-Wood Slab +126:3 Jungle-Wood Slab +126:4 Acacia Wood Slab +126:5 Dark Oak Wood Slab +127 Cocoa Plant +128 Sandstone Stairs +129 Emerald Ore +130 Ender Chest +131 Tripwire Hook +132 Tripwire +133 Block of Emerald +134 Wooden Stairs (Spruce) +135 Wooden Stairs (Birch) +136 Wooden Stairs (Jungle) +137 Command Block +138 Beacon +139 Cobblestone Wall +139:1 Mossy Cobblestone Wall +140 Flower Pot (Block) +141 Carrot (Crop) +142 Potatoes (Crop) +143 Button (Wood) +144 Head Block (Skeleton) +144:1 Head Block (Wither) +144:2 Head Block (Zombie) +144:3 Head Block (Steve) +144:4 Head Block (Creeper) +145 Anvil +145:1 Anvil (Slightly Damaged) +145:2 Anvil (Very Damaged) +146 Trapped Chest +147 Weighted Pressure Plate (Light) +148 Weighted Pressure Plate (Heavy) +149 Redstone Comparator (Off) +150 Redstone Comparator (On) +151 Daylight Sensor +152 Block of Redstone +153 Nether Quartz Ore +154 Hopper +155 Quartz Block +155:1 Chiseled Quartz Block +155:2 Pillar Quartz Block +156 Quartz Stairs +157 Rail (Activator) +158 Dropper +159 Stained Clay (White) +159:1 Stained Clay (Orange) +159:2 Stained Clay (Magenta) +159:3 Stained Clay (Light Blue) +159:4 Stained Clay (Yellow) +159:5 Stained Clay (Lime) +159:6 Stained Clay (Pink) +159:7 Stained Clay (Gray) +159:8 Stained Clay (Light Gray) +159:9 Stained Clay (Cyan) +159:10 Stained Clay (Purple) +159:11 Stained Clay (Blue) +159:12 Stained Clay (Brown) +159:13 Stained Clay (Green) +159:14 Stained Clay (Red) +159:15 Stained Clay (Black) +160 Stained Glass Pane (White) +160:1 Stained Glass Pane (Orange) +160:2 Stained Glass Pane (Magenta) +160:3 Stained Glass Pane (Light Blue) +160:4 Stained Glass Pane (Yellow) +160:5 Stained Glass Pane (Lime) +160:6 Stained Glass Pane (Pink) +160:7 Stained Glass Pane (Gray) +160:8 Stained Glass Pane (Light Gray) +160:9 Stained Glass Pane (Cyan) +160:10 Stained Glass Pane (Purple) +160:11 Stained Glass Pane (Blue) +160:12 Stained Glass Pane (Brown) +160:13 Stained Glass Pane (Green) +160:14 Stained Glass Pane (Red) +160:15 Stained Glass Pane (Black) +162 Wood (Acacia Oak) +162:1 Wood (Dark Oak) +163 Wooden Stairs (Acacia) +164 Wooden Stairs (Dark Oak) +170 Hay Bale +171 Carpet (White) +171:1 Carpet (Orange) +171:2 Carpet (Magenta) +171:3 Carpet (Light Blue) +171:4 Carpet (Yellow) +171:5 Carpet (Lime) +171:6 Carpet (Pink) +171:7 Carpet (Grey) +171:8 Carpet (Light Gray) +171:9 Carpet (Cyan) +171:10 Carpet (Purple) +171:11 Carpet (Blue) +171:12 Carpet (Brown) +171:13 Carpet (Green) +171:14 Carpet (Red) +171:15 Carpet (Black) +172 Hardened Clay +173 Block of Coal +174 Packed Ice +175 Sunflower +175:1 Lilac +175:2 Double Tallgrass +175:3 Large Fern +175:4 Rose Bush +175:5 Peony +256 Iron Shovel +257 Iron Pickaxe +258 Iron Axe +259 Flint and Steel +260 Apple +261 Bow +262 Arrow +263 Coal +263:1 Charcoal +264 Diamond Gem +265 Iron Ingot +266 Gold Ingot +267 Iron Sword +268 Wooden Sword +269 Wooden Shovel +270 Wooden Pickaxe +271 Wooden Axe +272 Stone Sword +273 Stone Shovel +274 Stone Pickaxe +275 Stone Axe +276 Diamond Sword +277 Diamond Shovel +278 Diamond Pickaxe +279 Diamond Axe +280 Stick +281 Bowl +282 Mushroom Stew +283 Gold Sword +284 Gold Shovel +285 Gold Pickaxe +286 Gold Axe +287 String +288 Feather +289 Gunpowder +290 Wooden Hoe +291 Stone Hoe +292 Iron Hoe +293 Diamond Hoe +294 Gold Hoe +295 Wheat Seeds +296 Wheat +297 Bread +298 Leather Helmet +299 Leather Chestplate +300 Leather Leggings +301 Leather Boots +302 Chainmail Helmet +303 Chainmail Chestplate +304 Chainmail Leggings +305 Chainmail Boots +306 Iron Helmet +307 Iron Chestplate +308 Iron Leggings +309 Iron Boots +310 Diamond Helmet +311 Diamond Chestplate +312 Diamond Leggings +313 Diamond Boots +314 Gold Helmet +315 Gold Chestplate +316 Gold Leggings +317 Gold Boots +318 Flint +319 Raw Porkchop +320 Cooked Porkchop +321 Painting +322 Golden Apple +322:1 Enchanted Golden Apple +323 Sign +324 Wooden Door +325 Bucket +326 Bucket (Water) +327 Bucket (Lava) +328 Minecart +329 Saddle +330 Iron Door +331 Redstone Dust +332 Snowball +333 Boat +334 Leather +335 Bucket (Milk) +336 Clay Brick +337 Clay +338 Sugar Cane +339 Paper +340 Book +341 Slime Ball +342 Minecart (Storage) +343 Minecart (Powered) +344 Egg +345 Compass +346 Fishing Rod +347 Watch +348 Glowstone Dust +349 Raw Fish +349:1 Raw Salmon +349:2 Clownfish +349:3 Pufferfish +350 Cooked Fish +350:1 Cooked Salmon +350:2 Clownfish +350:3 Pufferfish +351 Ink Sack +351:1 Rose Red Dye +351:2 Cactus Green Dye +351:3 Cocoa Bean +351:4 Lapis Lazuli +351:5 Purple Dye +351:6 Cyan Dye +351:7 Light Gray Dye +351:8 Gray Dye +351:9 Pink Dye +351:10 Lime Dye +351:11 Dandelion Yellow Dye +351:12 Light Blue Dye +351:13 Magenta Dye +351:14 Orange Dye +351:15 Bone Meal +352 Bone +353 Sugar +354 Cake +355 Bed +356 Redstone Repeater +357 Cookie +358 Map +359 Shears +360 Melon (Slice) +361 Pumpkin Seeds +362 Melon Seeds +363 Raw Beef +364 Steak +365 Raw Chicken +366 Cooked Chicken +367 Rotten Flesh +368 Ender Pearl +369 Blaze Rod +370 Ghast Tear +371 Gold Nugget +372 Nether Wart Seeds +373 Water Bottle +373:16 Awkward Potion +373:32 Thick Potion +373:64 Mundane Potion +373:8193 Regeneration Potion (0:45) +373:8194 Swiftness Potion (3:00) +373:8195 Fire Resistance Potion (3:00) +373:8196 Poison Potion (0:45) +373:8197 Healing Potion +373:8198 Night Vision Potion (3:00) +373:8200 Weakness Potion (1:30) +373:8201 Strength Potion (3:00) +373:8202 Slowness Potion (1:30) +373:8204 Harming Potion +373:8205 Water Breathing Potion (3:00) +373:8206 Invisibility Potion (3:00) +373:8225 Regeneration Potion II (0:22) +373:8226 Swiftness Potion II (1:30) +373:8228 Poison Potion II (0:22) +373:8229 Healing Potion II +373:8233 Strength Potion II (1:30) +373:8236 Harming Potion II +373:8257 Regeneration Potion (2:00) +373:8258 Swiftness Potion (8:00) +373:8259 Fire Resistance Potion (8:00) +373:8260 Poison Potion (2:00) +373:8262 Night Vision Potion (8:00) +373:8264 Weakness Potion (4:00) +373:8265 Strength Potion (8:00) +373:8266 Slowness Potion (4:00) +373:8269 Water Breathing Potion (8:00) +373:8270 Invisibility Potion (8:00) +373:8289 Regeneration Potion II (1:00) +373:8290 Swiftness Potion II (4:00) +373:8292 Poison Potion II (1:00) +373:8297 Strength Potion II (4:00) +373:16385 Regeneration Splash (0:33) +373:16386 Swiftness Splash (2:15) +373:16387 Fire Resistance Splash (2:15) +373:16388 Poison Splash (0:33) +373:16389 Healing Splash +373:16390 Night Vision Splash (2:15) +373:16392 Weakness Splash (1:07) +373:16393 Strength Splash (2:15) +373:16394 Slowness Splash (1:07) +373:16396 Harming Splash +373:16397 Breathing Splash (2:15) +373:16398 Invisibility Splash (2:15) +373:16417 Regeneration Splash II (0:16) +373:16418 Swiftness Splash II (1:07) +373:16420 Poison Splash II (0:16) +373:16421 Healing Splash II +373:16425 Strength Splash II (1:07) +373:16428 Harming Splash II +373:16449 Regeneration Splash (1:30) +373:16450 Swiftness Splash (6:00) +373:16451 Fire Resistance Splash (6:00) +373:16452 Poison Splash (1:30) +373:16454 Night Vision Splash (6:00) +373:16456 Weakness Splash (3:00) +373:16457 Strength Splash (6:00) +373:16458 Slowness Splash (3:00) +373:16461 Breathing Splash (6:00) +373:16462 Invisibility Splash (6:00) +373:16481 Regeneration Splash II (0:45) +373:16482 Swiftness Splash II (3:00) +373:16484 Poison Splash II (0:45) +373:16489 Strength Splash II (3:00) +374 Glass Bottle +375 Spider Eye +376 Fermented Spider Eye +377 Blaze Powder +378 Magma Cream +379 Brewing Stand +380 Cauldron +381 Eye of Ender +382 Glistering Melon (Slice) +383:50 Spawn Egg (Creeper) +383:51 Spawn Egg (Skeleton) +383:52 Spawn Egg (Spider) +383:54 Spawn Egg (Zombie) +383:55 Spawn Egg (Slime) +383:56 Spawn Egg (Ghast) +383:57 Spawn Egg (Zombie Pigmen) +383:58 Spawn Egg (Endermen) +383:59 Spawn Egg (Cave Spider) +383:60 Spawn Egg (Silverfish) +383:61 Spawn Egg (Blaze) +383:62 Spawn Egg (Magma Cube) +383:65 Spawn Egg (Bat) +383:66 Spawn Egg (Witch) +383:90 Spawn Egg (Pig) +383:91 Spawn Egg (Sheep) +383:92 Spawn Egg (Cow) +383:93 Spawn Egg (Chicken) +383:94 Spawn Egg (Squid) +383:95 Spawn Egg (Wolf) +383:96 Spawn Egg (Mooshroom) +383:98 Spawn Egg (Ocelot) +383:100 Spawn Egg (Horse) +383:120 Spawn Egg (Villager) +384 Bottle of Enchanting +385 Fire Charge +386 Book and Quill +387 Written Book +388 Emerald +389 Item Frame +390 Flower Pot +391 Carrot +392 Potato +393 Baked Potato +394 Poisonous Potato +395 Empty Map +396 Golden Carrot +397 Head (Skeleton) +397:1 Head (Wither) +397:2 Head (Zombie) +397:3 Head (Steve) +397:4 Head (Creeper) +398 Carrot on a Stick +399 Nether Star +400 Pumpkin Pie +401 Firework Rocket +402 Firework Star +403 Enchanted Book +404 Redstone Comparator +405 Nether Brick (Item) +406 Nether Quartz +407 Minecart (TNT) +408 Minecart (Hopper) +417 Iron Horse Armor +418 Gold Horse Armor +419 Diamond Horse Armor +420 Lead +421 Name Tag +422 Minecart (Command Block) +2256 Music Disk (13) +2257 Music Disk (Cat) +2258 Music Disk (Blocks) +2259 Music Disk (Chirp) +2260 Music Disk (Far) +2261 Music Disk (Mall) +2262 Music Disk (Mellohi) +2263 Music Disk (Stal) +2264 Music Disk (Strad) +2265 Music Disk (Ward) +2266 Music Disk (11) +2267 Music Disk (Wait) From 4e78c73d3f6e4b72da6d9535b9afc187c2cbd521 Mon Sep 17 00:00:00 2001 From: Denevien Date: Mon, 2 Dec 2013 13:41:10 -0600 Subject: [PATCH 4/5] Edited id search to properly display all sub-items when only given parent id search id 3 now properly returns both dirt and podzol, instead of just the podzol. --- ZomgBot/plugins/search.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ZomgBot/plugins/search.py b/ZomgBot/plugins/search.py index 969709e..88d0723 100644 --- a/ZomgBot/plugins/search.py +++ b/ZomgBot/plugins/search.py @@ -53,15 +53,21 @@ def search(search_type, term): return results if search_type == 'id': for set in items_list: + length = len(set) entry = set[0] if term.find(':') != -1: if term == entry: - results += set[0] + ': ' + set[1] + results += set[0] + ' - ' + set[1] if length > 2: for x in range(2, length): results += set[x] return results else: + if term == entry: + results += set[0] + ' - ' + set[1] + if length > 2: + for x in range(2, length): + results += set[x] if entry.find(':') != -1: stop = entry.find(':') id_num = entry[:stop] @@ -69,7 +75,7 @@ def search(search_type, term): current = '' if results != '': current += ', ' - current += set[0] + ': ' + set[1] + current += set[0] + ' - ' + set[1] if length > 2: for x in range(2, length): current += set[x] From 89631f144aaa494337540101b36bb88a98db2607 Mon Sep 17 00:00:00 2001 From: Denevien Date: Tue, 3 Dec 2013 00:04:11 -0600 Subject: [PATCH 5/5] Edited to not need "SEARCH_TYPE". Also added messages for invalid syntax and no results. --- ZomgBot/plugins/search.py | 65 +++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/ZomgBot/plugins/search.py b/ZomgBot/plugins/search.py index 88d0723..ebaac38 100644 --- a/ZomgBot/plugins/search.py +++ b/ZomgBot/plugins/search.py @@ -4,31 +4,50 @@ @Plugin.register(depends=["commands"]) class Search(Plugin): + def __init__(self): + self.items_list = [] + with open('items.txt') as inputfile: + for line in inputfile: + self.items_list.append(line.split()) + @Modifier.command("search") def cmd_search(self, context): if context.args[0:] == None: - return 'Use ".search SEARCH_TYPE INPUT". Possible search types are "name" and "id". When using "name", insert a one word keyword from a block type name to get a list of matching results. When using "id", enter a block id # to find the block name.' - inputs = context.args[0:] - inputs = inputs.split - if len(inputs) == 1: - if inputs == 'name': - return 'Use ".search name INPUT". The input should be a one word keyword from the block name. This will return a list of matching results.' - if inputs == 'id': - return 'Use ".search id INPUT". The input should be an item id, and will return any match(es)' - if len(inputs) > 2: - return 'Invalid syntax. Use ".search SEARCH_TYPE INPUT". Possible search types are "name" and "id". When using "name", insert a one word keyword from a block type name to get a list of matching results. When using "id", enter a block id # to find the block name.' + return 'Use ".search INPUT" where the INPUT is either a one word keyword or block id number' + given = context.args[0:] + given = given.split + if len(given) > 1: + return 'Invalid syntax. Use ".search INPUT" where the INPUT is either a one word keyword or block id number' else: - return search(inputs[0],inputs[1]) + return search(given) + def is_number(self, s): + try: + float(s) + return True + except ValueError: + return False - def search(search_type, term): - items_list = [] - with open('items.txt') as inputfile: - for line in inputfile: - items_list.append(line.split()) + def search(self, term): + error = 'Syntax Error: Please check for valid search parameters' + search_type = '' results = '' + if term.find(':') != -1: + loc = term.find(':') + if self.is_number(term[:loc]): + if self.is_number(term[loc + 1:]): + search_type = 'id' + else: + return error + else: + return error + else: + if self.is_number(term): + search_type = 'id' + else: + search_type = 'name' if search_type == 'name': - for set in items_list: + for set in self.items_list: length = len(set) for x in range(1,length): word = set[x] @@ -50,9 +69,12 @@ def search(search_type, term): for x in range(2, length): current += ' ' + set[x] results += current - return results + if results != '': + return results + else: + return 'No results found.' if search_type == 'id': - for set in items_list: + for set in self.items_list: length = len(set) entry = set[0] if term.find(':') != -1: @@ -80,4 +102,7 @@ def search(search_type, term): for x in range(2, length): current += set[x] results += current - return results + if results != '': + return results + else: + return 'No results found.'